mirror of https://github.com/TZGyn/shortener
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
630 B
TypeScript
32 lines
630 B
TypeScript
import { authenticateUser } from '$lib/server/auth'
|
|
import { redirect, type Handle } from '@sveltejs/kit'
|
|
|
|
export const handle: Handle = async ({ event, resolve }) => {
|
|
event.locals.user = await authenticateUser(event)
|
|
|
|
const pathname = event.url.pathname
|
|
|
|
const allowedPath = [
|
|
'/login',
|
|
'/signup',
|
|
'/api/login',
|
|
'/api/signup',
|
|
]
|
|
|
|
if (pathname === '/login' || pathname === 'signup') {
|
|
if (event.locals.user) {
|
|
throw redirect(303, '/')
|
|
}
|
|
}
|
|
|
|
if (!allowedPath.includes(pathname)) {
|
|
if (!event.locals.user) {
|
|
throw redirect(303, '/login')
|
|
}
|
|
}
|
|
|
|
const response = await resolve(event)
|
|
|
|
return response
|
|
}
|