Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions packages/data-sdk/src/stores/AuthenticationStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,7 @@ export class AuthenticationStore implements IAuthenticationStore {
}
}

async loginWithToken(
token: string,
refreshToken?: string,
skipUserFetch = false
) {
async loginWithToken(token: string, refreshToken?: string) {
const tokenData = JSON.parse(decode(token.split(".")[1]));
try {
let userId: string | undefined;
Expand All @@ -187,7 +183,7 @@ export class AuthenticationStore implements IAuthenticationStore {
userId = tokenData["formant:claims"].userId;
}

if (userId && this._currentUser?.id !== userId && !skipUserFetch) {
if (userId && this._currentUser?.id !== userId) {
const result = await fetch(`${this._apiUrl}/v1/admin/users/${userId}`, {
method: "GET",
headers: {
Expand All @@ -196,10 +192,15 @@ export class AuthenticationStore implements IAuthenticationStore {
},
});
const data = await result.json();
if (result.status !== 200) {
if (result.status === 404) {
// this can happen if the token doesn't have access to its own user, like in the embed case
// ignore this error
this._currentUser = undefined;
} else if (result.status !== 200) {
throw new Error(data.message);
} else {
this._currentUser = data;
}
this._currentUser = data;
}
this._token = token;
this._waitingForAuth.forEach((_) => _(true));
Expand Down