-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathauth.ts
More file actions
47 lines (43 loc) · 1.45 KB
/
auth.ts
File metadata and controls
47 lines (43 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { SvelteKitAuth } from "@auth/sveltekit";
import Keycloak from "@auth/sveltekit/providers/keycloak";
import {
AUTH_KEYCLOAK_ID,
AUTH_KEYCLOAK_ISSUER,
AUTH_KEYCLOAK_SECRET,
AUTH_SECRET,
} from "$env/static/private";
const authjsSecret = AUTH_SECRET; // Use Environment Variables AUTH_SECRET in prod
const kcConfig = {
issuer: AUTH_KEYCLOAK_ISSUER, // Use Environment Variables AUTH_KEYCLOAK_ISSUER in prod
clientId: AUTH_KEYCLOAK_ID, // Paste "Client id" here. Use Environment Variables AUTH_KEYCLOAK_ID in prod
clientSecret: AUTH_KEYCLOAK_SECRET, // Paste "Client secret" here. Use Environment Variables AUTH_KEYCLOAK_ISSUER in prod
};
export const { handle, signIn, signOut } = SvelteKitAuth({
trustHost: true,
secret: authjsSecret,
providers: [Keycloak(kcConfig)],
callbacks: {
jwt({ user, token, account, profile }) {
if (user) {
// User is available during sign-in
token.id = user.id;
}
if (profile) {
token.preferred_username = profile.preferred_username;
token.given_name = profile.given_name;
token.family_name = profile.family_name;
}
if (account) {
token.idToken = account.id_token;
token.accessToken = account.access_token;
token.refreshToken = account.refresh_token;
}
return token;
},
session({ session, token }) {
// session.user.id = token.id;
session.user = { ...token };
return session;
},
},
});