Skip to content

Commit ad6e6c3

Browse files
committed
hm
1 parent 7b45c9d commit ad6e6c3

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

services/src/public-api/auth/session.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,11 @@ declare module '@a-type/auth' {
1414
export const sessions = new SessionManager<Context<Env>>({
1515
getSessionConfig(ctx) {
1616
const apiUrl = new URL(ctx.env.API_ORIGIN);
17-
const apiDomain = apiUrl.hostname;
18-
// remove subdomains
19-
const domainParts = apiDomain.split('.');
20-
if (domainParts.length > 2) {
21-
apiUrl.hostname = domainParts.slice(1).join('.');
22-
}
2317
return {
2418
cookieName: 'alef-session',
2519
cookieOptions: {
2620
sameSite: 'lax',
27-
domain: apiUrl.hostname,
21+
domain: getRootDomain(apiUrl.hostname),
2822
},
2923
expiration: ctx.env.NODE_ENV === 'production' ? '1d' : '1m',
3024
async createSession(userId) {
@@ -60,3 +54,11 @@ export const sessions = new SessionManager<Context<Env>>({
6054
},
6155
},
6256
});
57+
58+
function getRootDomain(hostname: string) {
59+
const domainParts = hostname.split('.');
60+
if (domainParts.length > 2) {
61+
return domainParts.slice(-2).join('.');
62+
}
63+
return hostname;
64+
}

0 commit comments

Comments
 (0)