@@ -44,6 +44,7 @@ const authSetup = function () {
4444 const mode = qs [ 'mode' ] || 'signIn' ;
4545 let returnAppUrl = handleSpecificReturnUrl ( qs [ 'retUrl' ] , 'retUrl' ) ;
4646 let appUrl = qs [ 'appUrl' ] || false ;
47+ let onboardingWizardUrl = null ;
4748
4849 if ( utmSource &&
4950 ( utmSource != 'undefined' ) &&
@@ -229,6 +230,12 @@ const authSetup = function () {
229230 return token ? ! isTokenExpired ( token ) : false ;
230231 } ;
231232
233+ const redirectToOnboardingWizard = function ( ) {
234+ logger ( "redirect to onboarding wizard" ) ;
235+ const hostname = window . location . host . replace ( 'www.' , '' ) ;
236+ window . location = `https://platform.${ hostname } /onboard` ;
237+ }
238+
232239 const redirectToApp = function ( ) {
233240 logger ( "redirect to app" , appUrl ) ;
234241 if ( appUrl ) {
@@ -256,53 +263,59 @@ const authSetup = function () {
256263 }
257264
258265 const storeToken = function ( ) {
259- auth0 . getIdTokenClaims ( ) . then ( function ( claims ) {
260- idToken = claims . __raw ;
261- let userActive = false ;
262- Object . keys ( claims ) . findIndex ( function ( key ) {
263- if ( key . includes ( 'active' ) ) {
264- userActive = claims [ key ] ;
265- return true ;
266- }
267- return false ;
268- } ) ;
269- if ( userActive ) {
270- let tcsso = '' ;
266+ auth0 . getUser ( ) . then ( function ( user ) {
267+ auth0 . getIdTokenClaims ( ) . then ( function ( claims ) {
268+ idToken = claims . __raw ;
269+ let userActive = false ;
271270 Object . keys ( claims ) . findIndex ( function ( key ) {
272- if ( key . includes ( tcSSOCookie ) ) {
273- tcsso = claims [ key ] ;
271+ if ( key . includes ( 'active' ) ) {
272+ userActive = claims [ key ] ;
274273 return true ;
275274 }
276275 return false ;
277276 } ) ;
278- logger ( 'Storing token...' , true ) ;
279- try {
280- const exT = getCookieExpiry ( idToken ) ;
281- if ( exT ) {
282- setDomainCookie ( tcJWTCookie , idToken , exT ) ;
283- setDomainCookie ( v3JWTCookie , idToken , exT ) ;
284- setDomainCookie ( tcSSOCookie , tcsso , exT ) ;
285- } else {
286- setCookie ( tcJWTCookie , idToken , cookieExpireIn ) ;
287- setCookie ( v3JWTCookie , idToken , cookieExpireIn ) ;
288- setCookie ( tcSSOCookie , tcsso , cookieExpireIn ) ;
277+ if ( userActive ) {
278+ let tcsso = '' ;
279+ Object . keys ( claims ) . findIndex ( function ( key ) {
280+ if ( key . includes ( tcSSOCookie ) ) {
281+ tcsso = claims [ key ] ;
282+ return true ;
283+ }
284+ return false ;
285+ } ) ;
286+ logger ( 'Storing token...' , true ) ;
287+ try {
288+ const exT = getCookieExpiry ( idToken ) ;
289+ if ( exT ) {
290+ setDomainCookie ( tcJWTCookie , idToken , exT ) ;
291+ setDomainCookie ( v3JWTCookie , idToken , exT ) ;
292+ setDomainCookie ( tcSSOCookie , tcsso , exT ) ;
293+ } else {
294+ setCookie ( tcJWTCookie , idToken , cookieExpireIn ) ;
295+ setCookie ( v3JWTCookie , idToken , cookieExpireIn ) ;
296+ setCookie ( tcSSOCookie , tcsso , cookieExpireIn ) ;
297+ }
298+ } catch ( e ) {
299+ logger ( 'Error occured in fecthing token expiry time' , e . message ) ;
289300 }
290- } catch ( e ) {
291- logger ( 'Error occured in fecthing token expiry time' , e . message ) ;
292- }
293301
294- // session still active, but app calling login
295- if ( ! appUrl && returnAppUrl ) {
296- appUrl = returnAppUrl
302+ if ( user . show_onboarding_wizard ) {
303+ redirectToOnboardingWizard ( ) ;
304+ } else {
305+ // session still active, but app calling login
306+ if ( ! appUrl && returnAppUrl ) {
307+ appUrl = returnAppUrl
308+ }
309+ redirectToApp ( ) ;
310+ }
311+ } else {
312+ logger ( "User active ? " , userActive ) ;
313+ host = registerSuccessUrl ;
314+ logout ( ) ;
297315 }
298- redirectToApp ( ) ;
299- } else {
300- logger ( "User active ? " , userActive ) ;
301- host = registerSuccessUrl ;
302- logout ( ) ;
303- }
304- } ) . catch ( function ( e ) {
305- logger ( "Error in fetching token from auth0: " , e ) ;
316+ } ) . catch ( function ( e ) {
317+ logger ( "Error in fetching token from auth0: " , e ) ;
318+ } ) ;
306319 } ) ;
307320 } ;
308321
0 commit comments