@stacksjs/auth 0.70.88 → 0.70.91
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.
- package/dist/authentication.d.ts +43 -0
- package/dist/authentication.js +413 -0
- package/dist/authenticator.d.ts +17 -0
- package/dist/authenticator.js +14 -0
- package/dist/authorizable.d.ts +77 -0
- package/dist/authorizable.js +28 -0
- package/dist/client.d.ts +22 -0
- package/dist/client.js +26 -0
- package/dist/email-verification.d.ts +29 -0
- package/dist/email-verification.js +111 -0
- package/dist/gate.d.ts +180 -0
- package/dist/gate.js +203 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.js +26 -0
- package/dist/internal-constants.d.ts +19 -0
- package/dist/internal-constants.js +1 -0
- package/dist/middleware.d.ts +14 -0
- package/dist/middleware.js +28 -0
- package/dist/passkey.d.ts +97 -0
- package/dist/passkey.js +76 -0
- package/dist/password/reset.d.ts +10 -0
- package/dist/password/reset.js +156 -0
- package/dist/policy.d.ts +33 -0
- package/dist/policy.js +91 -0
- package/dist/rate-limiter.d.ts +44 -0
- package/dist/rate-limiter.js +91 -0
- package/dist/rbac-seed.d.ts +24 -0
- package/dist/rbac-seed.js +30 -0
- package/dist/rbac-store-bqb.d.ts +18 -0
- package/dist/rbac-store-bqb.js +180 -0
- package/dist/rbac.d.ts +265 -0
- package/dist/rbac.js +324 -0
- package/dist/register.d.ts +3 -0
- package/dist/register.js +43 -0
- package/dist/session-auth.d.ts +67 -0
- package/dist/session-auth.js +151 -0
- package/dist/team.d.ts +121 -0
- package/dist/team.js +88 -0
- package/dist/token.d.ts +16 -0
- package/dist/token.js +21 -0
- package/dist/tokens.d.ts +284 -0
- package/dist/tokens.js +489 -0
- package/dist/two-factor.d.ts +67 -0
- package/dist/two-factor.js +113 -0
- package/dist/user.d.ts +34 -0
- package/dist/user.js +41 -0
- 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.
|
|
5
|
+
"version": "0.70.91",
|
|
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.
|
|
59
|
-
"@stacksjs/router": "0.70.
|
|
58
|
+
"@stacksjs/error-handling": "0.70.91",
|
|
59
|
+
"@stacksjs/router": "0.70.91"
|
|
60
60
|
}
|
|
61
61
|
}
|