@@ -12,6 +12,7 @@ import { loginMiddlewareOAuth } from '@/server/lib/middleware/login';
1212import { deleteOAuthTokenCookie } from '@/server/lib/okta/tokens' ;
1313import { requestStateHasOAuthTokens } from '../lib/middleware/requestState' ;
1414import { JOBS_TOS_URI } from '@/shared/model/Configuration' ;
15+ import { buildUrlWithQueryParams } from '@/shared/lib/routeUtils' ;
1516
1617const { defaultReturnUri, signInPageUrl } = getConfiguration ( ) ;
1718
@@ -92,16 +93,16 @@ router.post(
9293 loginMiddlewareOAuth ,
9394 async ( req : Request , res : ResponseWithRequestState ) => {
9495 const state = res . locals ;
96+ const { queryParams } = state ;
97+ const { firstName, secondName } = req . body ;
98+
9599 if ( ! requestStateHasOAuthTokens ( state ) ) {
96100 return res . redirect (
97101 303 ,
98- addQueryParamsToUntypedPath ( signInPageUrl , state . queryParams ) ,
102+ addQueryParamsToUntypedPath ( signInPageUrl , queryParams ) ,
99103 ) ;
100104 }
101105
102- const { returnUrl, fromURI } = state . queryParams ;
103- const { firstName, secondName } = req . body ;
104-
105106 try {
106107 await setupJobsUserInOkta (
107108 firstName ,
@@ -121,17 +122,12 @@ router.post(
121122 error ,
122123 ) ;
123124 trackMetric ( 'JobsGRSGroupAgree::Failure' ) ;
124- } finally {
125- // complete the oauth flow if coming from the okta sign in page
126- // through the oauth flow initiated by the jobs site
127- if ( fromURI ) {
128- // eslint-disable-next-line no-unsafe-finally -- we want to redirect and return regardless of any throws
129- return res . redirect ( 303 , fromURI ) ;
130- }
131- // otherwise try going to the return url
132- // eslint-disable-next-line no-unsafe-finally -- we want to redirect and return regardless of any throws
133- return res . redirect ( 303 , returnUrl ) ;
134125 }
126+
127+ return res . redirect (
128+ 303 ,
129+ buildUrlWithQueryParams ( '/welcome/complete-account' , { } , queryParams ) ,
130+ ) ;
135131 } ,
136132) ;
137133
0 commit comments