diff --git a/.changeset/gentle-swans-sleep.md b/.changeset/gentle-swans-sleep.md new file mode 100644 index 00000000..83479eb5 --- /dev/null +++ b/.changeset/gentle-swans-sleep.md @@ -0,0 +1,6 @@ +--- +'@asgardeo/javascript': patch +'@asgardeo/react': patch +--- + +Throw JWT verification errors diff --git a/packages/javascript/src/IsomorphicCrypto.ts b/packages/javascript/src/IsomorphicCrypto.ts index 2ff20aed..b399704c 100644 --- a/packages/javascript/src/IsomorphicCrypto.ts +++ b/packages/javascript/src/IsomorphicCrypto.ts @@ -124,6 +124,9 @@ export class IsomorphicCrypto { 'ID token validation returned false', ), ); + }) + .catch((error: AsgardeoAuthException) => { + return Promise.reject(error); }); } diff --git a/packages/react/src/contexts/Asgardeo/AsgardeoProvider.tsx b/packages/react/src/contexts/Asgardeo/AsgardeoProvider.tsx index 040bf646..699d3fe6 100644 --- a/packages/react/src/contexts/Asgardeo/AsgardeoProvider.tsx +++ b/packages/react/src/contexts/Asgardeo/AsgardeoProvider.tsx @@ -180,9 +180,12 @@ const AsgardeoProvider: FC> = ({ } // setError(null); } catch (error) { - if (error && Object.prototype.hasOwnProperty.call(error, 'code')) { - // setError(error); - } + throw new AsgardeoRuntimeError( + `Sign in failed: ${error instanceof Error ? error.message : String(JSON.stringify(error))}`, + 'asgardeo-signIn-Error', + 'react', + 'An error occurred while trying to sign in.', + ); } } else { // TODO: Add a debug log to indicate that the user is not signed in @@ -418,7 +421,12 @@ const AsgardeoProvider: FC> = ({ return response as User; } catch (error) { - throw new Error(`Error while signing in: ${error instanceof Error ? error.message : String(error)}`); + throw new AsgardeoRuntimeError( + `Sign in failed: ${error instanceof Error ? error.message : String(JSON.stringify(error))}`, + 'asgardeo-signIn-Error', + 'react', + 'An error occurred while trying to sign in.', + ); } finally { if (!isV2FlowRequest) { setIsUpdatingSession(false); @@ -440,7 +448,7 @@ const AsgardeoProvider: FC> = ({ return response; } catch (error) { throw new AsgardeoRuntimeError( - `Error while signing in silently: ${error.message || error}`, + `Error while signing in silently: ${error instanceof Error ? error.message : String(JSON.stringify(error))}`, 'asgardeo-signInSilently-Error', 'react', 'An error occurred while trying to sign in silently.', @@ -462,7 +470,7 @@ const AsgardeoProvider: FC> = ({ } } catch (error) { throw new AsgardeoRuntimeError( - `Failed to switch organization: ${error.message || error}`, + `Failed to switch organization: ${error instanceof Error ? error.message : String(JSON.stringify(error))}`, 'asgardeo-switchOrganization-Error', 'react', 'An error occurred while switching to the specified organization.',