-
-
Notifications
You must be signed in to change notification settings - Fork 92
/
[...].ts
36 lines (35 loc) · 1.12 KB
/
[...].ts
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
import { NuxtAuthHandler } from "#auth";
import GithubProvider from "next-auth/providers/github";
import GoogleProvider from "next-auth/providers/google";
const nuxtAuthHandler = NuxtAuthHandler({
secret: useRuntimeConfig().authSecret,
providers: [
// @ts-ignore
GithubProvider.default({
clientId: useRuntimeConfig().githubClientId,
clientSecret: useRuntimeConfig().githubClientSecret,
httpOptions: {
timeout: 10000,
},
}),
// @ts-ignore
GoogleProvider.default({
clientId: useRuntimeConfig().googleClientId,
clientSecret: useRuntimeConfig().googleClientSecret,
}),
],
});
export default defineEventHandler(async (event) => {
const result = await nuxtAuthHandler(event);
const headerCookies = event.node.res.getHeader("set-cookie");
if (headerCookies && typeof headerCookies === "string") {
const sessionToken = headerCookies
.split(/,(?!\s)/)
.find((v) => v.includes("session-token"));
if (sessionToken) {
event.node.res.removeHeader("set-cookie");
event.node.res.setHeader("set-cookie", sessionToken);
}
}
return result;
});