mirror of
https://github.com/stack-auth/stack.git
synced 2026-06-04 21:04:37 +08:00
fixed access token parsing
This commit is contained in:
parent
4ead6a73b4
commit
3a55713b43
@ -1,5 +1,5 @@
|
||||
import * as yup from 'yup';
|
||||
import { JWTExpired } from 'jose/errors';
|
||||
import { JWTExpired, JOSEError } from 'jose/errors';
|
||||
import { decryptJWT, encryptJWT } from '@stackframe/stack-shared/dist/utils/jwt';
|
||||
import { StatusError } from '@stackframe/stack-shared/dist/utils/errors';
|
||||
import { KnownErrors } from '@stackframe/stack-shared';
|
||||
@ -19,6 +19,8 @@ export async function decodeAccessToken(accessToken: string) {
|
||||
} catch (error) {
|
||||
if (error instanceof JWTExpired) {
|
||||
throw new KnownErrors.AccessTokenExpired();
|
||||
} else if (error instanceof JOSEError) {
|
||||
throw new KnownErrors.UnparsableAccessToken();
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
|
||||
@ -309,7 +309,7 @@ export class StackClientInterface {
|
||||
const processedRes = await this._processResponse(rawRes);
|
||||
if (processedRes.status === "error") {
|
||||
// If the access token is expired, reset it and retry
|
||||
if (processedRes.error instanceof KnownErrors.AccessTokenExpired) {
|
||||
if (processedRes.error instanceof KnownErrors.InvalidAccessToken) {
|
||||
tokenStore.set({
|
||||
accessToken: null,
|
||||
refreshToken: tokenObj.refreshToken,
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import * as jose from "jose";
|
||||
import { getEnvVariable } from "./env";
|
||||
import { KnownErrors } from "..";
|
||||
|
||||
const SERVER_SECRET = jose.base64url.decode(getEnvVariable("SERVER_SECRET"));
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user