Skip to content

Commit 886f98b

Browse files
authored
fix(auth): improve OpenID token error handling (#1928)
In packages/zudoku/src/lib/authentication/providers/openid.tsx destructure setLoggedOut and call it to mark the user logged out when provider data is missing or when token exchange fails. Replace the previous silent return of an empty string with an AuthorizationError when no refresh token is present. Also call setLoggedOut and throw an AuthorizationError when the token refresh response lacks an access token. These changes keep the authentication state consistent and surface explicit errors to callers instead of returning empty tokens that could lead to incorrect downstream behavior.
1 parent cead1db commit 886f98b

File tree

1 file changed

+5
-2
lines changed
  • packages/zudoku/src/lib/authentication/providers

1 file changed

+5
-2
lines changed

packages/zudoku/src/lib/authentication/providers/openid.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,10 @@ export class OpenIDAuthenticationProvider
218218

219219
async getAccessToken(): Promise<string> {
220220
const as = await this.getAuthServer();
221-
const { providerData } = useAuthState.getState();
221+
const { providerData, setLoggedOut } = useAuthState.getState();
222+
222223
if (!providerData) {
224+
setLoggedOut();
223225
throw new AuthorizationError("User is not authenticated");
224226
}
225227
const tokenState = providerData as OpenIdProviderData;
@@ -232,7 +234,7 @@ export class OpenIDAuthenticationProvider
232234
profile: null,
233235
providerData: null,
234236
});
235-
return "";
237+
throw new AuthorizationError("No refresh token found");
236238
}
237239

238240
const request = await oauth.refreshTokenGrantRequest(
@@ -247,6 +249,7 @@ export class OpenIDAuthenticationProvider
247249
);
248250

249251
if (!response.access_token) {
252+
setLoggedOut();
250253
throw new AuthorizationError("No access token in response");
251254
}
252255

0 commit comments

Comments
 (0)