@@ -45,13 +45,18 @@ const githubAuthCallback = (req, res, next) => {
45
45
const rdsUiUrl = new URL ( config . get ( "services.rdsUi.baseUrl" ) ) ;
46
46
let authRedirectionUrl = rdsUiUrl ;
47
47
let devMode = false ;
48
+ let isV2FlagPresent = false ;
49
+
48
50
if ( "state" in req . query ) {
49
51
try {
50
52
const redirectUrl = new URL ( req . query . state ) ;
51
53
if ( redirectUrl . searchParams . get ( "isMobileApp" ) === "true" ) {
52
54
isMobileApp = true ;
53
55
redirectUrl . searchParams . delete ( "isMobileApp" ) ;
54
56
}
57
+
58
+ if ( redirectUrl . searchParams . get ( "v2" ) === "true" ) isV2FlagPresent = true ;
59
+
55
60
if ( `.${ redirectUrl . hostname } ` . endsWith ( `.${ rdsUiUrl . hostname } ` ) ) {
56
61
// Matching *.realdevsquad.com
57
62
authRedirectionUrl = redirectUrl ;
@@ -78,18 +83,25 @@ const githubAuthCallback = (req, res, next) => {
78
83
updated_at : Date . now ( ) ,
79
84
} ;
80
85
81
- const { userId, incompleteUserDetails } = await users . addOrUpdate ( userData ) ;
86
+ const { userId, incompleteUserDetails, role } = await users . addOrUpdate ( userData ) ;
82
87
83
88
const token = authService . generateAuthToken ( { userId } ) ;
84
89
85
- // respond with a cookie
86
- res . cookie ( config . get ( "userToken.cookieName" ) , token , {
90
+ const cookieOptions = {
87
91
domain : rdsUiUrl . hostname ,
88
92
expires : new Date ( Date . now ( ) + config . get ( "userToken.ttl" ) * 1000 ) ,
89
93
httpOnly : true ,
90
94
secure : true ,
91
95
sameSite : "lax" ,
92
- } ) ;
96
+ } ;
97
+ // respond with a cookie
98
+ res . cookie ( config . get ( "userToken.cookieName" ) , token , cookieOptions ) ;
99
+
100
+ /* redirectUrl woud be like https://realdevsquad.com?v2=true */
101
+ if ( isV2FlagPresent ) {
102
+ const tokenV2 = authService . generateAuthToken ( { userId, role } ) ;
103
+ res . cookie ( config . get ( "userToken.cookieV2Name" ) , tokenV2 , cookieOptions ) ;
104
+ }
93
105
94
106
if ( ! devMode ) {
95
107
// TODO: Revisit incompleteUserDetails redirect condition
@@ -112,12 +124,15 @@ const githubAuthCallback = (req, res, next) => {
112
124
const signout = ( req , res ) => {
113
125
const cookieName = config . get ( "userToken.cookieName" ) ;
114
126
const rdsUiUrl = new URL ( config . get ( "services.rdsUi.baseUrl" ) ) ;
115
- res . clearCookie ( cookieName , {
127
+ const cookieOptions = {
116
128
domain : rdsUiUrl . hostname ,
117
129
httpOnly : true ,
118
130
secure : true ,
119
131
sameSite : "lax" ,
120
- } ) ;
132
+ } ;
133
+ res . clearCookie ( cookieName , cookieOptions ) ;
134
+ const cookieV2Name = config . get ( "userToken.cookieV2Name" ) ;
135
+ res . clearCookie ( cookieV2Name , cookieOptions ) ;
121
136
return res . json ( {
122
137
message : "Signout successful" ,
123
138
} ) ;
0 commit comments