File tree Expand file tree Collapse file tree 1 file changed +9
-8
lines changed
packages/data-sdk/src/stores Expand file tree Collapse file tree 1 file changed +9
-8
lines changed Original file line number Diff line number Diff line change @@ -161,11 +161,7 @@ export class AuthenticationStore implements IAuthenticationStore {
161
161
}
162
162
}
163
163
164
- async loginWithToken (
165
- token : string ,
166
- refreshToken ?: string ,
167
- skipUserFetch = false
168
- ) {
164
+ async loginWithToken ( token : string , refreshToken ?: string ) {
169
165
const tokenData = JSON . parse ( decode ( token . split ( "." ) [ 1 ] ) ) ;
170
166
try {
171
167
let userId : string | undefined ;
@@ -187,7 +183,7 @@ export class AuthenticationStore implements IAuthenticationStore {
187
183
userId = tokenData [ "formant:claims" ] . userId ;
188
184
}
189
185
190
- if ( userId && this . _currentUser ?. id !== userId && ! skipUserFetch ) {
186
+ if ( userId && this . _currentUser ?. id !== userId ) {
191
187
const result = await fetch ( `${ this . _apiUrl } /v1/admin/users/${ userId } ` , {
192
188
method : "GET" ,
193
189
headers : {
@@ -196,10 +192,15 @@ export class AuthenticationStore implements IAuthenticationStore {
196
192
} ,
197
193
} ) ;
198
194
const data = await result . json ( ) ;
199
- if ( result . status !== 200 ) {
195
+ if ( result . status === 404 ) {
196
+ // this can happen if the token doesn't have access to its own user, like in the embed case
197
+ // ignore this error
198
+ this . _currentUser = undefined ;
199
+ } else if ( result . status !== 200 ) {
200
200
throw new Error ( data . message ) ;
201
+ } else {
202
+ this . _currentUser = data ;
201
203
}
202
- this . _currentUser = data ;
203
204
}
204
205
this . _token = token ;
205
206
this . _waitingForAuth . forEach ( ( _ ) => _ ( true ) ) ;
You can’t perform that action at this time.
0 commit comments