Added handle for UI
This commit is contained in:
parent
6c4dd63ee9
commit
177382d9c3
@ -8,7 +8,7 @@ const sessionConstructorHandle = (async ({event, resolve}) => {
|
|||||||
|
|
||||||
const data = await AppData.extractAppDataFromCookies(event.cookies)
|
const data = await AppData.extractAppDataFromCookies(event.cookies)
|
||||||
|
|
||||||
logger.debug(`Session Data: ${data}`, "Session Handle")
|
logger.debug(`User: ${data?.user.username}\nToken ${data?.session.sessionToken}`, "Session Handle")
|
||||||
|
|
||||||
event.locals.session = data
|
event.locals.session = data
|
||||||
|
|
||||||
@ -27,6 +27,7 @@ const apiHandle = (async ({event, resolve}) => {
|
|||||||
return await resolve(event)
|
return await resolve(event)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// It's a backend, should not redirect
|
||||||
if (!event.locals.session) {
|
if (!event.locals.session) {
|
||||||
// Satisfies HTTP Codes:
|
// Satisfies HTTP Codes:
|
||||||
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/401
|
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/401
|
||||||
@ -37,7 +38,27 @@ const apiHandle = (async ({event, resolve}) => {
|
|||||||
|
|
||||||
}) satisfies Handle
|
}) satisfies Handle
|
||||||
|
|
||||||
|
const appHandle = (async ({event, resolve}) => {
|
||||||
|
|
||||||
|
logger.debug(event.url.pathname, "API Handle")
|
||||||
|
logger.debug(`Session Data: ${event.locals.session}`, "API Handle")
|
||||||
|
|
||||||
|
if(!event.url.pathname.startsWith("/app/program")) {
|
||||||
|
// next handle
|
||||||
|
return await resolve(event)
|
||||||
|
}
|
||||||
|
|
||||||
|
// It's for frontend, should redirect
|
||||||
|
if (!event.locals.session) {
|
||||||
|
return redirect(302, "/app/login")
|
||||||
|
}
|
||||||
|
|
||||||
|
return await resolve(event)
|
||||||
|
|
||||||
|
}) satisfies Handle
|
||||||
|
|
||||||
export const handles = sequence(
|
export const handles = sequence(
|
||||||
sessionConstructorHandle,
|
sessionConstructorHandle,
|
||||||
apiHandle
|
apiHandle,
|
||||||
|
appHandle
|
||||||
)
|
)
|
||||||
Loading…
x
Reference in New Issue
Block a user