mirror of https://github.com/TZGyn/shortener
added user in app layout load
parent
d4cda54f46
commit
5d6c8a1f2b
@ -1,7 +1,22 @@
|
|||||||
|
import { getUserFromSessionToken } from '$lib/server/auth'
|
||||||
|
import { redirect } from '@sveltejs/kit'
|
||||||
import type { LayoutServerLoad } from './$types'
|
import type { LayoutServerLoad } from './$types'
|
||||||
|
|
||||||
export const load = (async () => {
|
export const load = (async (event) => {
|
||||||
|
const token = event.cookies.get('token')
|
||||||
|
|
||||||
|
if (!token) {
|
||||||
|
throw redirect(303, '/')
|
||||||
|
}
|
||||||
|
|
||||||
|
const user = await getUserFromSessionToken(token)
|
||||||
|
|
||||||
|
if (!user) {
|
||||||
|
throw redirect(303, '/')
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
shortener_url: process.env.SHORTENER_URL ?? 's.tzgyn.com',
|
shortener_url: process.env.SHORTENER_URL ?? 's.tzgyn.com',
|
||||||
|
user: user,
|
||||||
}
|
}
|
||||||
}) satisfies LayoutServerLoad
|
}) satisfies LayoutServerLoad
|
||||||
|
|||||||
Loading…
Reference in New Issue