Skip to content

Commit fc91736

Browse files
committedDec 7, 2023
chore: 🔧 add sessionKey
1 parent 5be787e commit fc91736

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed
 

‎README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,10 @@ export const handle = sequence(
7878
);
7979
auth.use(oauthStrategy);
8080
event.locals.auth = auth;
81-
event.locals.user = event.locals.session.get('user');
81+
event.locals.user = event.locals.session.get(
82+
// replace your session key, AuthOptions.sessionKey
83+
'user'
84+
);
8285
const response = await resolve(event);
8386

8487
return response;

‎package.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,9 @@
4141
"!dist/**/*.test.*",
4242
"!dist/**/*.spec.*"
4343
],
44-
"dependencies": {
45-
"@svelte-dev/session": "^0.1.0"
46-
},
44+
"dependencies": {},
4745
"peerDependencies": {
46+
"@svelte-dev/session": "^0.1.0",
4847
"@sveltejs/kit": "^1.0.0",
4948
"svelte": "^5.0.0||^4.0.0"
5049
},

‎src/lib/auth/strategy.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export abstract class Strategy<User, VerifyOptions> {
9191
// if a successRedirect is not set, we return the user
9292
if (!options.successRedirect) return user;
9393
const session = (event.locals as any).session as SessionStorage;
94-
await session.set('user', user);
94+
await session.set(options?.sessionKey ?? 'user', user);
9595
await session.set('strategy', this.name);
9696
throw redirect(307, options.successRedirect);
9797
}

‎src/lib/auth/types.ts

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ export interface AuthOptions {
77
* The name used to register the strategy
88
*/
99
name?: string;
10+
/**
11+
* The key of the session used to set the user data.
12+
* @default "user"
13+
*/
14+
sessionKey?: string;
1015
/**
1116
* In what key of the session the errors will be set.
1217
* @default "auth:error"

0 commit comments

Comments
 (0)
Please sign in to comment.