I'm trying to protect routes, or redirect to the login when auth_token
isn't in local storage.
In my src/routes/+layout.server.ts
I have:
import { redirect } from "@sveltejs/kit"
import type { LayoutServerLoad } from "./$types"
export const load: LayoutServerLoad = async ({ locals }) => {
if (localStorage.getItem('auth_token') === null) {
throw redirect(303, '/')
}
}
Although I'm getting:
ReferenceError: localStorage is not defined?