Svemix provides you with some nice utilities for handling responses.
This is a shortcut for sending 30x responses.
<script context="module" lang="ts" ssr>
import type { Action } from 'svemix';
import { redirect } from 'svemix/server';
export const action: Action = async ({ locals }) => {
const user = locals.session.data.user;
if (!user) {
return redirect('/login');
/**
instead of
return {
status: 302,
headers: {
location: '/login'
}
}
**/
}
return {
ok: true
};
};
</script>