Compare commits
No commits in common. "022d727394dece36c1e13e48b8f8f461a7568260" and "3a684a5d5a28a2ea321736bc5840be3f813be21e" have entirely different histories.
022d727394
...
3a684a5d5a
17
src/auth.ts
17
src/auth.ts
@ -9,21 +9,4 @@ export const { handle, signIn, signOut } = SvelteKitAuth({
|
|||||||
clientSecret: AUTHENTIK_SECRET,
|
clientSecret: AUTHENTIK_SECRET,
|
||||||
issuer: AUTHENTIK_ISSUER,
|
issuer: AUTHENTIK_ISSUER,
|
||||||
})],
|
})],
|
||||||
callbacks: {
|
|
||||||
// this feels like an extremely hacky way to get nickname and groups into the session object
|
|
||||||
// TODO: investigate if there's a better way to do this
|
|
||||||
jwt: async ({token, profile}) => {
|
|
||||||
if(profile){
|
|
||||||
token.nickname = profile.nickname;
|
|
||||||
token.groups = profile.groups;
|
|
||||||
}
|
|
||||||
return token;
|
|
||||||
},
|
|
||||||
session: async ({session, token}) => {
|
|
||||||
session.user.nickname = token.nickname;
|
|
||||||
session.user.groups = token.groups;
|
|
||||||
return session;
|
|
||||||
},
|
|
||||||
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
@ -2,32 +2,28 @@ import { authenticateUser } from "$lib/js/authenticate"
|
|||||||
import type { Handle } from "@sveltejs/kit"
|
import type { Handle } from "@sveltejs/kit"
|
||||||
import { redirect } from "@sveltejs/kit"
|
import { redirect } from "@sveltejs/kit"
|
||||||
import { error } from "@sveltejs/kit"
|
import { error } from "@sveltejs/kit"
|
||||||
import { SvelteKitAuth } from "@auth/sveltekit"
|
export { handle } from "./auth"
|
||||||
import Authentik from "@auth/core/providers/authentik"
|
|
||||||
import { AUTHENTIK_ID, AUTHENTIK_SECRET, AUTHENTIK_ISSUER } from "$env/static/private";
|
|
||||||
import { sequence } from "@sveltejs/kit/hooks"
|
|
||||||
import * as auth from "./auth"
|
|
||||||
|
|
||||||
async function authorization({ event, resolve }) {
|
//export const handle : Handle = async({event, resolve}) => {
|
||||||
// Protect any routes under /authenticated
|
// if(event.url.pathname.startsWith('/rezepte/edit') || event.url.pathname.startsWith('/rezepte/add')){
|
||||||
if (event.url.pathname.startsWith('/rezepte/edit') || event.url.pathname.startsWith('/rezepte/add')) {
|
// event.locals.user = await authenticateUser(event.cookies)
|
||||||
const session = await event.locals.getSession();
|
// if(!event.locals.user){
|
||||||
if (!session) {
|
// throw redirect(303, "/login")
|
||||||
throw redirect(303, '/auth/signin');
|
// }
|
||||||
}
|
// else if(!event.locals.user.access.includes("rezepte")){
|
||||||
else if (! session.user.groups.includes('rezepte_users')) {
|
// throw error(401, "Your user does not have access to this page")
|
||||||
// strip last dir from url
|
// }
|
||||||
// TODO: give indication of why access failed
|
// }
|
||||||
const new_url = event.url.pathname.split('/').slice(0, -1).join('/');
|
// else if(event.url.pathname.startsWith('/abrechnung')){
|
||||||
throw redirect(303, new_url);
|
// event.locals.user = await authenticateUser(event.cookies)
|
||||||
}
|
// if(!event.locals.user){
|
||||||
}
|
// throw redirect(303, "/login")
|
||||||
|
// }
|
||||||
// If the request is still here, just proceed as normally
|
// else if(!event.locals.user.access.includes("abrechnung")){
|
||||||
return resolve(event);
|
// throw error(401, "Your User does not have access to this page")
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
export const handle: Handle = sequence(
|
//
|
||||||
auth.handle,
|
// const response = await resolve(event)
|
||||||
authorization
|
// return response
|
||||||
);
|
//}
|
||||||
|
Loading…
Reference in New Issue
Block a user