Skip to content

Commit e018507

Browse files
authored
Merge pull request #271 from brionmario/fix-asgardeo-v2-signup
fix: properly throw JWT verification errors
2 parents 9a1a9cb + a035bed commit e018507

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

.changeset/gentle-swans-sleep.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@asgardeo/javascript': patch
3+
'@asgardeo/react': patch
4+
---
5+
6+
Throw JWT verification errors

packages/javascript/src/IsomorphicCrypto.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ export class IsomorphicCrypto<T = any> {
124124
'ID token validation returned false',
125125
),
126126
);
127+
})
128+
.catch((error: AsgardeoAuthException) => {
129+
return Promise.reject(error);
127130
});
128131
}
129132

packages/react/src/contexts/Asgardeo/AsgardeoProvider.tsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,12 @@ const AsgardeoProvider: FC<PropsWithChildren<AsgardeoProviderProps>> = ({
180180
}
181181
// setError(null);
182182
} catch (error) {
183-
if (error && Object.prototype.hasOwnProperty.call(error, 'code')) {
184-
// setError(error);
185-
}
183+
throw new AsgardeoRuntimeError(
184+
`Sign in failed: ${error instanceof Error ? error.message : String(JSON.stringify(error))}`,
185+
'asgardeo-signIn-Error',
186+
'react',
187+
'An error occurred while trying to sign in.',
188+
);
186189
}
187190
} else {
188191
// TODO: Add a debug log to indicate that the user is not signed in
@@ -418,7 +421,12 @@ const AsgardeoProvider: FC<PropsWithChildren<AsgardeoProviderProps>> = ({
418421

419422
return response as User;
420423
} catch (error) {
421-
throw new Error(`Error while signing in: ${error instanceof Error ? error.message : String(error)}`);
424+
throw new AsgardeoRuntimeError(
425+
`Sign in failed: ${error instanceof Error ? error.message : String(JSON.stringify(error))}`,
426+
'asgardeo-signIn-Error',
427+
'react',
428+
'An error occurred while trying to sign in.',
429+
);
422430
} finally {
423431
if (!isV2FlowRequest) {
424432
setIsUpdatingSession(false);
@@ -440,7 +448,7 @@ const AsgardeoProvider: FC<PropsWithChildren<AsgardeoProviderProps>> = ({
440448
return response;
441449
} catch (error) {
442450
throw new AsgardeoRuntimeError(
443-
`Error while signing in silently: ${error.message || error}`,
451+
`Error while signing in silently: ${error instanceof Error ? error.message : String(JSON.stringify(error))}`,
444452
'asgardeo-signInSilently-Error',
445453
'react',
446454
'An error occurred while trying to sign in silently.',
@@ -462,7 +470,7 @@ const AsgardeoProvider: FC<PropsWithChildren<AsgardeoProviderProps>> = ({
462470
}
463471
} catch (error) {
464472
throw new AsgardeoRuntimeError(
465-
`Failed to switch organization: ${error.message || error}`,
473+
`Failed to switch organization: ${error instanceof Error ? error.message : String(JSON.stringify(error))}`,
466474
'asgardeo-switchOrganization-Error',
467475
'react',
468476
'An error occurred while switching to the specified organization.',

0 commit comments

Comments
 (0)