File tree Expand file tree Collapse file tree 1 file changed +9
-7
lines changed
services/src/public-api/auth Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Original file line number Diff line number Diff line change @@ -14,17 +14,11 @@ declare module '@a-type/auth' {
1414export 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+ }
You can’t perform that action at this time.
0 commit comments