@@ -80,7 +80,7 @@ export type LoginPayload = {
8080 resumeSessionOnly ?: boolean
8181 givenSessionToken ?: string
8282 ecOnly ?: boolean
83- fromSessionToken ?: Uint8Array | null
83+ primaryAccountSessionTokenForLinking ?: Uint8Array | null
8484}
8585
8686export enum UserType {
@@ -113,6 +113,11 @@ export type EncryptionKeys = {
113113 eccPrivateKey : Uint8Array ;
114114}
115115
116+ export const enum LoginV3ResultEnum {
117+ NOT_LOGGED_IN = 'notLoggedin' ,
118+ LINKING_BLOCKED_BY_CROSS_REGION = 'linkingBlockedByCrossRegion' ,
119+ }
120+
116121export class Auth {
117122 ssoLogoutUrl : string = ''
118123 userType : UserType = UserType . normal
@@ -277,9 +282,9 @@ export class Auth {
277282 resumeSessionOnly = false ,
278283 givenSessionToken = undefined ,
279284 ecOnly = false ,
280- fromSessionToken = undefined
285+ primaryAccountSessionTokenForLinking = undefined
281286 } : Partial < LoginPayload >
282- ) {
287+ ) : Promise < { result : LoginV3ResultEnum } | undefined > {
283288 this . _username = username || this . options . sessionStorage ?. lastUsername || ''
284289
285290 let wrappedPassword : KeyWrapper | undefined ;
@@ -324,7 +329,7 @@ export class Auth {
324329 loginMethod : loginMethod ,
325330 cloneCode : await this . options . sessionStorage ?. getCloneCode ( this . options . host as KeeperEnvironment , this . _username ) ,
326331 v2TwoFactorToken : v2TwoFactorToken ,
327- fromSessionToken,
332+ fromSessionToken : primaryAccountSessionTokenForLinking ,
328333 } )
329334 if ( loginType !== LoginType . NORMAL && ! ! loginType ) {
330335 startLoginRequest . loginType = loginType
@@ -357,7 +362,7 @@ export class Auth {
357362 }
358363 if ( resumeSessionOnly && loginResponse && ( loginResponse . loginState != Authentication . LoginState . LOGGED_IN ) ) {
359364 return {
360- result : 'notLoggedin'
365+ result : LoginV3ResultEnum . NOT_LOGGED_IN ,
361366 }
362367 }
363368 console . log ( loginResponse )
@@ -395,7 +400,7 @@ export class Auth {
395400 break ;
396401 case Authentication . LoginState . DEVICE_APPROVAL_REQUIRED :
397402 case Authentication . LoginState . REQUIRES_DEVICE_ENCRYPTED_DATA_KEY :
398- if ( givenSessionToken ) return { result : 'notLoggedin' }
403+ if ( givenSessionToken ) return { result : LoginV3ResultEnum . NOT_LOGGED_IN }
399404 try {
400405 loginToken = await this . verifyDevice ( username , loginResponse . encryptedLoginToken , loginResponse . loginState == Authentication . LoginState . REQUIRES_DEVICE_ENCRYPTED_DATA_KEY )
401406 } catch ( e : any ) {
@@ -407,6 +412,12 @@ export class Auth {
407412 handleError ( 'license_expired' , loginResponse , new Error ( loginResponse . message ) )
408413 return ;
409414 case Authentication . LoginState . REGION_REDIRECT :
415+ if ( ! ! primaryAccountSessionTokenForLinking ) {
416+ return {
417+ result : LoginV3ResultEnum . LINKING_BLOCKED_BY_CROSS_REGION ,
418+ }
419+ }
420+
410421 // TODO: put region_redirect in its own loop since
411422 // its unique to the other states.
412423 this . options . host = loginResponse . stateSpecificValue
0 commit comments