Update @auth/sveltekit to latest stable version 1.10.0
- Upgraded @auth/sveltekit from 0.14.0 to 1.10.0 - Updated session API from event.locals.getSession() to event.locals.auth() - Fixed TypeScript definitions for new auth API in app.d.ts - Updated layout server load functions to use LayoutServerLoad type - Fixed session callbacks with proper token type casting - Switched to generic OIDC provider config to resolve issuer validation issues - All auth functionality now working with latest Auth.js version 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
18
src/app.d.ts
vendored
18
src/app.d.ts
vendored
@@ -1,12 +1,28 @@
|
||||
// See https://kit.svelte.dev/docs/types#app
|
||||
// for information about these interfaces
|
||||
import type { Session } from "@auth/sveltekit";
|
||||
|
||||
declare global {
|
||||
namespace App {
|
||||
// interface Error {}
|
||||
// interface Locals {}
|
||||
interface Locals {
|
||||
auth(): Promise<Session | null>;
|
||||
}
|
||||
// interface PageData {}
|
||||
// interface Platform {}
|
||||
}
|
||||
}
|
||||
|
||||
declare module "@auth/sveltekit" {
|
||||
interface Session {
|
||||
user?: {
|
||||
name?: string | null;
|
||||
email?: string | null;
|
||||
image?: string | null;
|
||||
nickname?: string;
|
||||
groups?: string[];
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export {};
|
||||
|
14
src/auth.ts
14
src/auth.ts
@@ -4,11 +4,17 @@ import { AUTHENTIK_ID, AUTHENTIK_SECRET, AUTHENTIK_ISSUER } from "$env/static/pr
|
||||
|
||||
export const { handle, signIn, signOut } = SvelteKitAuth({
|
||||
providers: [
|
||||
Authentik({
|
||||
{
|
||||
id: "authentik",
|
||||
name: "Authentik",
|
||||
type: "oidc",
|
||||
clientId: AUTHENTIK_ID,
|
||||
clientSecret: AUTHENTIK_SECRET,
|
||||
issuer: AUTHENTIK_ISSUER,
|
||||
})],
|
||||
checks: ["state"],
|
||||
}],
|
||||
trustHost: true,
|
||||
debug: process.env.NODE_ENV === "development",
|
||||
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
|
||||
@@ -20,8 +26,8 @@ export const { handle, signIn, signOut } = SvelteKitAuth({
|
||||
return token;
|
||||
},
|
||||
session: async ({session, token}) => {
|
||||
session.user.nickname = token.nickname;
|
||||
session.user.groups = token.groups;
|
||||
session.user.nickname = token.nickname as string;
|
||||
session.user.groups = token.groups as string[];
|
||||
return session;
|
||||
},
|
||||
|
||||
|
@@ -10,7 +10,7 @@ import * as auth from "./auth"
|
||||
async function authorization({ event, resolve }) {
|
||||
// Protect any routes under /authenticated
|
||||
if (event.url.pathname.startsWith('/rezepte/edit') || event.url.pathname.startsWith('/rezepte/add')) {
|
||||
const session = await event.locals.getSession();
|
||||
const session = await event.locals.auth();
|
||||
if (!session) {
|
||||
redirect(303, '/auth/signin');
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import type { PageServerLoad } from "./$types"
|
||||
import type { LayoutServerLoad } from "./$types"
|
||||
|
||||
export const load : PageServerLoad = (async ({locals}) => {
|
||||
export const load : LayoutServerLoad = (async ({locals}) => {
|
||||
return {
|
||||
session: await locals.auth(),
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import type { PageServerLoad } from "./$types"
|
||||
import type { LayoutServerLoad } from "./$types"
|
||||
|
||||
export const load : PageServerLoad = (async ({locals}) => {
|
||||
export const load : LayoutServerLoad = (async ({locals}) => {
|
||||
return {
|
||||
session: await locals.auth(),
|
||||
}
|
||||
|
@@ -2,10 +2,6 @@
|
||||
import Header from '$lib/components/Header.svelte'
|
||||
import UserHeader from '$lib/components/UserHeader.svelte';
|
||||
export let data
|
||||
let username = ""
|
||||
if(data.user){
|
||||
username = data.user.username
|
||||
}
|
||||
</script>
|
||||
<Header>
|
||||
<ul class=site_header slot=links>
|
||||
@@ -13,6 +9,6 @@ if(data.user){
|
||||
<li><a href="/glaube/rosenkranz">Rosenkranz</a></li>
|
||||
<li><a href="/glaube/predigten">Predigten</a></li>
|
||||
</ul>
|
||||
<UserHeader {username} slot=right_side></UserHeader>
|
||||
<UserHeader user={data.session?.user} slot=right_side></UserHeader>
|
||||
<slot></slot>
|
||||
</Header>
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import type { PageServerLoad } from "./$types"
|
||||
import type { LayoutServerLoad } from "./$types"
|
||||
|
||||
export const load : PageServerLoad = async ({locals}) => {
|
||||
export const load : LayoutServerLoad = async ({locals}) => {
|
||||
return {
|
||||
session: await locals.auth()
|
||||
}
|
||||
|
@@ -1,5 +1,6 @@
|
||||
export async function load({locals}) {
|
||||
const session = await locals.auth();
|
||||
return {
|
||||
user: locals.user
|
||||
user: session?.user
|
||||
};
|
||||
};
|
||||
|
@@ -1,10 +1,11 @@
|
||||
import type { PageLoad } from "./$types";
|
||||
import type { PageServerLoad } from "./$types";
|
||||
|
||||
export async function load({ fetch, params, locals}) {
|
||||
let current_month = new Date().getMonth() + 1
|
||||
const res = await fetch(`/api/rezepte/items/${params.name}`);
|
||||
const recipe = await res.json();
|
||||
const session = await locals.auth();
|
||||
return {recipe: recipe,
|
||||
user: locals.user
|
||||
user: session?.user
|
||||
};
|
||||
};
|
||||
|
Reference in New Issue
Block a user