@@ -9,6 +9,7 @@ export enum AuthStatus {
9
9
SignedIn = 'signed-in' ,
10
10
SignedOut = 'signed-out' ,
11
11
Interstitial = 'interstitial' ,
12
+ Handshake = 'handshake' ,
12
13
Unknown = 'unknown' ,
13
14
}
14
15
@@ -28,6 +29,7 @@ export type SignedInState = {
28
29
isInterstitial : false ;
29
30
isUnknown : false ;
30
31
toAuth : ( ) => SignedInAuthObject ;
32
+ headers : Headers | null ;
31
33
} ;
32
34
33
35
export type SignedOutState = {
@@ -46,6 +48,7 @@ export type SignedOutState = {
46
48
isInterstitial : false ;
47
49
isUnknown : false ;
48
50
toAuth : ( ) => SignedOutAuthObject ;
51
+ headers : Headers | null ;
49
52
} ;
50
53
51
54
export type InterstitialState = Omit < SignedOutState , 'isInterstitial' | 'status' | 'toAuth' > & {
@@ -54,13 +57,29 @@ export type InterstitialState = Omit<SignedOutState, 'isInterstitial' | 'status'
54
57
toAuth : ( ) => null ;
55
58
} ;
56
59
60
+ export type HandshakeState = Omit < SignedOutState , 'headers' | 'status' | 'toAuth' > & {
61
+ status : AuthStatus . Handshake ;
62
+ headers : Headers ;
63
+ isInterstitial : false ;
64
+ toAuth : ( ) => null ;
65
+ } ;
66
+
57
67
export type UnknownState = Omit < InterstitialState , 'status' | 'isInterstitial' | 'isUnknown' > & {
58
68
status : AuthStatus . Unknown ;
59
69
isInterstitial : false ;
60
70
isUnknown : true ;
61
71
} ;
62
72
63
73
export enum AuthErrorReason {
74
+ SessionTokenMissing = 'session-token-missing' ,
75
+ SessionTokenWithoutClientUAT = 'session-token-but-no-client-uat' ,
76
+ ClientUATWithoutSessionToken = 'client-uat-but-no-session-token' ,
77
+ SessionTokenOutdated = 'session-token-outdated' ,
78
+ ClockSkew = 'clock-skew' ,
79
+ UnexpectedError = 'unexpected-error' ,
80
+ Unknown = 'unknown' ,
81
+
82
+ // Delete these old crap
64
83
CookieAndUATMissing = 'cookie-and-uat-missing' ,
65
84
CookieMissing = 'cookie-missing' ,
66
85
CookieOutDated = 'cookie-outdated' ,
@@ -73,13 +92,11 @@ export enum AuthErrorReason {
73
92
PrimaryRespondsToSyncing = 'primary-responds-to-syncing' ,
74
93
StandardSignedIn = 'standard-signed-in' ,
75
94
StandardSignedOut = 'standard-signed-out' ,
76
- UnexpectedError = 'unexpected-error' ,
77
- Unknown = 'unknown' ,
78
95
}
79
96
80
97
export type AuthReason = AuthErrorReason | TokenVerificationErrorReason ;
81
98
82
- export type RequestState = SignedInState | SignedOutState | InterstitialState | UnknownState ;
99
+ export type RequestState = SignedInState | SignedOutState | InterstitialState | HandshakeState | UnknownState ;
83
100
84
101
type LoadResourcesOptions = {
85
102
loadSession ?: boolean ;
@@ -99,12 +116,16 @@ type RequestStateParams = {
99
116
} ;
100
117
101
118
type AuthParams = {
102
- /* Client token cookie value */
103
- cookieToken ?: string ;
119
+ /* Session token cookie value */
120
+ sessionTokenInCookie ?: string ;
121
+ /* Client token header value */
122
+ sessionTokenInHeader ?: string ;
104
123
/* Client uat cookie value */
105
124
clientUat ?: string ;
106
- /* Client token header value */
107
- headerToken ?: string ;
125
+ /* DevBrowser token value */
126
+ devBrowserToken ?: string ;
127
+ /* Handshake token value */
128
+ handshakeToken ?: string ;
108
129
} ;
109
130
110
131
export type AuthStatusOptionsType = LoadResourcesOptions &
@@ -115,6 +136,7 @@ export type AuthStatusOptionsType = LoadResourcesOptions &
115
136
export async function signedIn < T extends AuthStatusOptionsType > (
116
137
options : T ,
117
138
sessionClaims : JwtPayload ,
139
+ headers : Headers | null = null ,
118
140
) : Promise < SignedInState > {
119
141
const {
120
142
publishableKey = '' ,
@@ -128,8 +150,8 @@ export async function signedIn<T extends AuthStatusOptionsType>(
128
150
secretKey,
129
151
apiUrl,
130
152
apiVersion,
131
- cookieToken ,
132
- headerToken ,
153
+ sessionTokenInCookie ,
154
+ sessionTokenInHeader ,
133
155
loadSession,
134
156
loadUser,
135
157
loadOrganization,
@@ -159,7 +181,7 @@ export async function signedIn<T extends AuthStatusOptionsType>(
159
181
secretKey,
160
182
apiUrl,
161
183
apiVersion,
162
- token : cookieToken || headerToken || '' ,
184
+ token : sessionTokenInCookie || sessionTokenInHeader || '' ,
163
185
session,
164
186
user,
165
187
organization,
@@ -183,12 +205,14 @@ export async function signedIn<T extends AuthStatusOptionsType>(
183
205
isInterstitial : false ,
184
206
isUnknown : false ,
185
207
toAuth : ( ) => authObject ,
208
+ headers,
186
209
} ;
187
210
}
188
211
export function signedOut < T extends AuthStatusOptionsType > (
189
212
options : T ,
190
213
reason : AuthReason ,
191
214
message = '' ,
215
+ headers : Headers | null = null ,
192
216
) : SignedOutState {
193
217
const {
194
218
publishableKey = '' ,
@@ -216,6 +240,7 @@ export function signedOut<T extends AuthStatusOptionsType>(
216
240
isSignedIn : false ,
217
241
isInterstitial : false ,
218
242
isUnknown : false ,
243
+ headers,
219
244
toAuth : ( ) => signedOutAuthObject ( { ...options , status : AuthStatus . SignedOut , reason, message } ) ,
220
245
} ;
221
246
}
@@ -252,6 +277,44 @@ export function interstitial<T extends AuthStatusOptionsType>(
252
277
isInterstitial : true ,
253
278
isUnknown : false ,
254
279
toAuth : ( ) => null ,
280
+ headers : new Headers ( ) ,
281
+ } ;
282
+ }
283
+
284
+ export function handshake < T extends AuthStatusOptionsType > (
285
+ options : T ,
286
+ reason : AuthReason ,
287
+ message = '' ,
288
+ headers : Headers ,
289
+ ) : HandshakeState {
290
+ const {
291
+ publishableKey = '' ,
292
+ proxyUrl = '' ,
293
+ isSatellite = false ,
294
+ domain = '' ,
295
+ signInUrl = '' ,
296
+ signUpUrl = '' ,
297
+ afterSignInUrl = '' ,
298
+ afterSignUpUrl = '' ,
299
+ } = options ;
300
+
301
+ return {
302
+ status : AuthStatus . Handshake ,
303
+ reason,
304
+ message,
305
+ publishableKey,
306
+ isSatellite,
307
+ domain,
308
+ proxyUrl,
309
+ signInUrl,
310
+ signUpUrl,
311
+ afterSignInUrl,
312
+ afterSignUpUrl,
313
+ isSignedIn : false ,
314
+ isUnknown : false ,
315
+ headers,
316
+ isInterstitial : false ,
317
+ toAuth : ( ) => null ,
255
318
} ;
256
319
}
257
320
@@ -283,5 +346,6 @@ export function unknownState(options: AuthStatusOptionsType, reason: AuthReason,
283
346
isInterstitial : false ,
284
347
isUnknown : true ,
285
348
toAuth : ( ) => null ,
349
+ headers : new Headers ( ) ,
286
350
} ;
287
351
}
0 commit comments