Skip to content

Commit

Permalink
fix: use reject instead of throw (#1134)
Browse files Browse the repository at this point in the history
Co-authored-by: pilcrowOnPaper <[email protected]>
  • Loading branch information
giacomoferretti and pilcrowonpaper authored Sep 18, 2023
1 parent 13a333a commit 8507a53
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .auri/$8145tnre.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
package: "lucia"
type: "patch"
---

Fix unhandled rejection error when using `AuthRequest.validate()` and `AuthRequest.validateBearerToken()`
8 changes: 4 additions & 4 deletions packages/lucia/src/auth/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export class AuthRequest<_Auth extends Auth = any> {
debug.request.info("Using cached result for session validation");
return this.validatePromise;
}
this.validatePromise = new Promise(async (resolve) => {
this.validatePromise = new Promise(async (resolve, reject) => {
if (!this.storedSessionId) return resolve(null);
try {
const session = await this.auth.validateSession(this.storedSessionId);
Expand All @@ -140,7 +140,7 @@ export class AuthRequest<_Auth extends Auth = any> {
this.maybeSetSession(null);
return resolve(null);
}
throw e;
return reject(e);
}
});

Expand All @@ -152,7 +152,7 @@ export class AuthRequest<_Auth extends Auth = any> {
debug.request.info("Using cached result for bearer token validation");
return this.validatePromise;
}
this.validatePromise = new Promise(async (resolve) => {
this.validatePromise = new Promise(async (resolve, reject) => {
if (!this.bearerToken) return resolve(null);
try {
const session = await this.auth.validateSession(this.bearerToken);
Expand All @@ -161,7 +161,7 @@ export class AuthRequest<_Auth extends Auth = any> {
if (e instanceof LuciaError) {
return resolve(null);
}
throw e;
return reject(e);
}
});

Expand Down

0 comments on commit 8507a53

Please sign in to comment.