@stacksjs/auth 0.70.88 → 0.70.90

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.
Files changed (47) hide show
  1. package/dist/authentication.d.ts +43 -0
  2. package/dist/authentication.js +413 -0
  3. package/dist/authenticator.d.ts +17 -0
  4. package/dist/authenticator.js +14 -0
  5. package/dist/authorizable.d.ts +77 -0
  6. package/dist/authorizable.js +28 -0
  7. package/dist/client.d.ts +22 -0
  8. package/dist/client.js +26 -0
  9. package/dist/email-verification.d.ts +29 -0
  10. package/dist/email-verification.js +111 -0
  11. package/dist/gate.d.ts +180 -0
  12. package/dist/gate.js +203 -0
  13. package/dist/index.d.ts +36 -0
  14. package/dist/index.js +26 -0
  15. package/dist/internal-constants.d.ts +19 -0
  16. package/dist/internal-constants.js +1 -0
  17. package/dist/middleware.d.ts +14 -0
  18. package/dist/middleware.js +28 -0
  19. package/dist/passkey.d.ts +97 -0
  20. package/dist/passkey.js +76 -0
  21. package/dist/password/reset.d.ts +10 -0
  22. package/dist/password/reset.js +156 -0
  23. package/dist/policy.d.ts +33 -0
  24. package/dist/policy.js +91 -0
  25. package/dist/rate-limiter.d.ts +44 -0
  26. package/dist/rate-limiter.js +91 -0
  27. package/dist/rbac-seed.d.ts +24 -0
  28. package/dist/rbac-seed.js +30 -0
  29. package/dist/rbac-store-bqb.d.ts +18 -0
  30. package/dist/rbac-store-bqb.js +180 -0
  31. package/dist/rbac.d.ts +265 -0
  32. package/dist/rbac.js +324 -0
  33. package/dist/register.d.ts +3 -0
  34. package/dist/register.js +43 -0
  35. package/dist/session-auth.d.ts +67 -0
  36. package/dist/session-auth.js +151 -0
  37. package/dist/team.d.ts +121 -0
  38. package/dist/team.js +88 -0
  39. package/dist/token.d.ts +16 -0
  40. package/dist/token.js +21 -0
  41. package/dist/tokens.d.ts +284 -0
  42. package/dist/tokens.js +489 -0
  43. package/dist/two-factor.d.ts +67 -0
  44. package/dist/two-factor.js +113 -0
  45. package/dist/user.d.ts +34 -0
  46. package/dist/user.js +41 -0
  47. package/package.json +3 -3
package/dist/user.d.ts ADDED
@@ -0,0 +1,34 @@
1
+ import type { UserModel as OrmUserModel } from '@stacksjs/orm';
2
+ /**
3
+ * Get the currently authenticated user
4
+ *
5
+ * This is the primary way to get the authenticated user in your application.
6
+ * It first checks if the user was already set by the auth middleware,
7
+ * then falls back to validating the bearer token.
8
+ *
9
+ * @example
10
+ * import { authUser } from '@stacksjs/auth'
11
+ *
12
+ * const user = await authUser()
13
+ * if (user) {
14
+ * console.log('Logged in as:', user.email)
15
+ * }
16
+ */
17
+ export declare function authUser(): Promise<UserModel | undefined>;
18
+ /**
19
+ * Alias for authUser() - for backwards compatibility
20
+ * @deprecated Use authUser() instead
21
+ */
22
+ export declare function getCurrentUser(): Promise<UserModel | undefined>;
23
+ export declare function check(): Promise<boolean>;
24
+ export declare function id(): Promise<number | undefined>;
25
+ export declare function email(): Promise<string | undefined>;
26
+ export declare function name(): Promise<string | undefined>;
27
+ export declare function isAuthenticated(): Promise<boolean>;
28
+ export declare function logout(): Promise<void>;
29
+ export declare function refresh(): Promise<void>;
30
+ // Local aliases — keep the existing `UserModel` / `UserJsonResponse` symbols
31
+ // in this module while sourcing the underlying type from the ORM.
32
+ declare type UserModel = OrmUserModel;
33
+ declare type UserJsonResponse = OrmUserModel;
34
+ export type AuthUser = UserJsonResponse;
package/dist/user.js ADDED
@@ -0,0 +1,41 @@
1
+ import { request } from "@stacksjs/router";
2
+ import { Auth } from "./authentication";
3
+ export async function authUser() {
4
+ const middlewareUser = request?._authenticatedUser;
5
+ if (middlewareUser)
6
+ return middlewareUser;
7
+ let token = request.bearerToken?.();
8
+ if (!token) {
9
+ const authHeader = request.headers?.get?.("authorization") || request.headers?.get?.("Authorization");
10
+ if (authHeader && authHeader.startsWith("Bearer "))
11
+ token = authHeader.substring(7);
12
+ }
13
+ if (!token)
14
+ return;
15
+ return await Auth.getUserFromToken(token);
16
+ }
17
+ export async function getCurrentUser() {
18
+ return authUser();
19
+ }
20
+ export async function check() {
21
+ return !!await authUser();
22
+ }
23
+ export async function id() {
24
+ return (await authUser())?.id;
25
+ }
26
+ export async function email() {
27
+ return (await authUser())?.email;
28
+ }
29
+ export async function name() {
30
+ return (await authUser())?.name;
31
+ }
32
+ export async function isAuthenticated() {
33
+ return await check();
34
+ }
35
+ export async function logout() {
36
+ await Auth.logout();
37
+ }
38
+ export async function refresh() {
39
+ if (request?._authenticatedUser)
40
+ request._authenticatedUser = void 0;
41
+ }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@stacksjs/auth",
3
3
  "type": "module",
4
4
  "sideEffects": false,
5
- "version": "0.70.88",
5
+ "version": "0.70.90",
6
6
  "description": "A more simplistic way to authenticate.",
7
7
  "author": "Chris Breuer",
8
8
  "contributors": [
@@ -55,7 +55,7 @@
55
55
  },
56
56
  "devDependencies": {
57
57
  "better-dx": "^0.2.16",
58
- "@stacksjs/error-handling": "0.70.88",
59
- "@stacksjs/router": "0.70.88"
58
+ "@stacksjs/error-handling": "0.70.90",
59
+ "@stacksjs/router": "0.70.90"
60
60
  }
61
61
  }