Skip to content

Commit 7eb909b

Browse files
Fixed 404 user not found error for service account (#210)
1 parent e871112 commit 7eb909b

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

packages/data-sdk/src/stores/AuthenticationStore.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,7 @@ export class AuthenticationStore implements IAuthenticationStore {
161161
}
162162
}
163163

164-
async loginWithToken(
165-
token: string,
166-
refreshToken?: string,
167-
skipUserFetch = false
168-
) {
164+
async loginWithToken(token: string, refreshToken?: string) {
169165
const tokenData = JSON.parse(decode(token.split(".")[1]));
170166
try {
171167
let userId: string | undefined;
@@ -187,7 +183,7 @@ export class AuthenticationStore implements IAuthenticationStore {
187183
userId = tokenData["formant:claims"].userId;
188184
}
189185

190-
if (userId && this._currentUser?.id !== userId && !skipUserFetch) {
186+
if (userId && this._currentUser?.id !== userId) {
191187
const result = await fetch(`${this._apiUrl}/v1/admin/users/${userId}`, {
192188
method: "GET",
193189
headers: {
@@ -196,10 +192,15 @@ export class AuthenticationStore implements IAuthenticationStore {
196192
},
197193
});
198194
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) {
200200
throw new Error(data.message);
201+
} else {
202+
this._currentUser = data;
201203
}
202-
this._currentUser = data;
203204
}
204205
this._token = token;
205206
this._waitingForAuth.forEach((_) => _(true));

0 commit comments

Comments
 (0)