@stacksjs/auth 0.72.94 → 0.72.96

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -28,6 +28,13 @@ export declare function authMiddleware(request: any): Promise<void>;
28
28
  *
29
29
  * Resolving it here means every caller agrees on what "the user" is, and the
30
30
  * answer is a user rather than a callable.
31
+ *
32
+ * It is also the answer to "is this a user at all". An object with no usable
33
+ * `id` is not one, and returning it anyway pushed the failure downstream into
34
+ * RBAC, which validates its input and throws a TypeError — so an authorization
35
+ * middleware answered 500 rather than 401, to signed-in and anonymous callers
36
+ * alike. Deciding it here means every caller's own `if (!user) throw 401` is
37
+ * the check that fires.
31
38
  */
32
39
  export declare function authenticatedUser(request: any): Promise<any | undefined>;
33
40
  /**
@@ -1 +1 @@
1
- import{Auth}from"./authentication";import{requestToken}from"./request-token";export async function authMiddleware(request){const bearerToken=requestToken(request);if(!bearerToken){const error=Error("No authentication token provided.");error.statusCode=401;throw error}const user=await Auth.getUserFromToken(bearerToken);if(!user){const error=Error("Invalid or expired authentication token.");error.statusCode=401;throw error}Auth.setUser(user);request._authenticatedUser=user;const accessToken=await Auth.currentAccessToken();request._currentAccessToken=accessToken}export const authMiddlewareHandler={name:"auth",handle:authMiddleware};export async function authenticatedUser(request){const cached=request?._authenticatedUser;if(cached&&typeof cached==="object")return cached;const macro=request?.user;if(typeof macro==="function"){const resolved=await macro();return resolved&&typeof resolved==="object"?resolved:void 0}if(macro&&typeof macro==="object")return macro;return}
1
+ import{Auth}from"./authentication";import{requestToken}from"./request-token";export async function authMiddleware(request){const bearerToken=requestToken(request);if(!bearerToken){const error=Error("No authentication token provided.");error.statusCode=401;throw error}const user=await Auth.getUserFromToken(bearerToken);if(!user){const error=Error("Invalid or expired authentication token.");error.statusCode=401;throw error}Auth.setUser(user);request._authenticatedUser=user;const accessToken=await Auth.currentAccessToken();request._currentAccessToken=accessToken}export const authMiddlewareHandler={name:"auth",handle:authMiddleware};export async function authenticatedUser(request){const cached=request?._authenticatedUser;if(isUserLike(cached))return cached;const macro=request?.user;if(typeof macro==="function"){const resolved=await macro();return isUserLike(resolved)?resolved:void 0}if(isUserLike(macro))return macro;return}function isUserLike(value){if(!value||typeof value!=="object")return!1;const id=value.id;if(typeof id==="number")return Number.isFinite(id)&&id>0;return typeof id==="string"&&id.trim().length>0}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@stacksjs/auth",
3
3
  "type": "module",
4
4
  "sideEffects": false,
5
- "version": "0.72.94",
5
+ "version": "0.72.96",
6
6
  "description": "A more simplistic way to authenticate.",
7
7
  "author": "Chris Breuer",
8
8
  "contributors": [
@@ -61,7 +61,7 @@
61
61
  },
62
62
  "devDependencies": {
63
63
  "better-dx": "^0.2.24",
64
- "@stacksjs/error-handling": "0.72.94",
65
- "@stacksjs/router": "0.72.94"
64
+ "@stacksjs/error-handling": "0.72.96",
65
+ "@stacksjs/router": "0.72.96"
66
66
  }
67
67
  }