@revealui/auth 0.0.0-canary-20260409021642
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/LICENSE +22 -0
- package/README.md +115 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/react/index.d.ts +19 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +12 -0
- package/dist/react/useMFA.d.ts +83 -0
- package/dist/react/useMFA.d.ts.map +1 -0
- package/dist/react/useMFA.js +182 -0
- package/dist/react/usePasskey.d.ts +88 -0
- package/dist/react/usePasskey.d.ts.map +1 -0
- package/dist/react/usePasskey.js +203 -0
- package/dist/react/useSession.d.ts +32 -0
- package/dist/react/useSession.d.ts.map +1 -0
- package/dist/react/useSession.js +109 -0
- package/dist/react/useSignIn.d.ts +47 -0
- package/dist/react/useSignIn.d.ts.map +1 -0
- package/dist/react/useSignIn.js +121 -0
- package/dist/react/useSignOut.d.ts +30 -0
- package/dist/react/useSignOut.d.ts.map +1 -0
- package/dist/react/useSignOut.js +57 -0
- package/dist/react/useSignUp.d.ts +43 -0
- package/dist/react/useSignUp.d.ts.map +1 -0
- package/dist/react/useSignUp.js +106 -0
- package/dist/server/audit-bridge.d.ts +69 -0
- package/dist/server/audit-bridge.d.ts.map +1 -0
- package/dist/server/audit-bridge.js +169 -0
- package/dist/server/auth.d.ts +46 -0
- package/dist/server/auth.d.ts.map +1 -0
- package/dist/server/auth.js +393 -0
- package/dist/server/brute-force.d.ts +53 -0
- package/dist/server/brute-force.d.ts.map +1 -0
- package/dist/server/brute-force.js +163 -0
- package/dist/server/errors.d.ts +28 -0
- package/dist/server/errors.d.ts.map +1 -0
- package/dist/server/errors.js +51 -0
- package/dist/server/index.d.ts +30 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +23 -0
- package/dist/server/magic-link.d.ts +52 -0
- package/dist/server/magic-link.d.ts.map +1 -0
- package/dist/server/magic-link.js +111 -0
- package/dist/server/mfa-enforcement.d.ts +76 -0
- package/dist/server/mfa-enforcement.d.ts.map +1 -0
- package/dist/server/mfa-enforcement.js +76 -0
- package/dist/server/mfa.d.ts +90 -0
- package/dist/server/mfa.d.ts.map +1 -0
- package/dist/server/mfa.js +304 -0
- package/dist/server/oauth.d.ts +97 -0
- package/dist/server/oauth.d.ts.map +1 -0
- package/dist/server/oauth.js +370 -0
- package/dist/server/passkey.d.ts +132 -0
- package/dist/server/passkey.d.ts.map +1 -0
- package/dist/server/passkey.js +269 -0
- package/dist/server/password-reset.d.ts +72 -0
- package/dist/server/password-reset.d.ts.map +1 -0
- package/dist/server/password-reset.js +289 -0
- package/dist/server/password-validation.d.ts +25 -0
- package/dist/server/password-validation.d.ts.map +1 -0
- package/dist/server/password-validation.js +52 -0
- package/dist/server/providers/github.d.ts +14 -0
- package/dist/server/providers/github.d.ts.map +1 -0
- package/dist/server/providers/github.js +86 -0
- package/dist/server/providers/google.d.ts +11 -0
- package/dist/server/providers/google.d.ts.map +1 -0
- package/dist/server/providers/google.js +68 -0
- package/dist/server/providers/vercel.d.ts +11 -0
- package/dist/server/providers/vercel.d.ts.map +1 -0
- package/dist/server/providers/vercel.js +68 -0
- package/dist/server/rate-limit.d.ts +54 -0
- package/dist/server/rate-limit.d.ts.map +1 -0
- package/dist/server/rate-limit.js +148 -0
- package/dist/server/session.d.ts +111 -0
- package/dist/server/session.d.ts.map +1 -0
- package/dist/server/session.js +416 -0
- package/dist/server/signed-cookie.d.ts +32 -0
- package/dist/server/signed-cookie.d.ts.map +1 -0
- package/dist/server/signed-cookie.js +67 -0
- package/dist/server/storage/database.d.ts +26 -0
- package/dist/server/storage/database.d.ts.map +1 -0
- package/dist/server/storage/database.js +110 -0
- package/dist/server/storage/in-memory.d.ts +28 -0
- package/dist/server/storage/in-memory.d.ts.map +1 -0
- package/dist/server/storage/in-memory.js +80 -0
- package/dist/server/storage/index.d.ts +34 -0
- package/dist/server/storage/index.d.ts.map +1 -0
- package/dist/server/storage/index.js +94 -0
- package/dist/server/storage/interface.d.ts +46 -0
- package/dist/server/storage/interface.d.ts.map +1 -0
- package/dist/server/storage/interface.js +6 -0
- package/dist/types.d.ts +78 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +8 -0
- package/dist/utils/database.d.ts +53 -0
- package/dist/utils/database.d.ts.map +1 -0
- package/dist/utils/database.js +151 -0
- package/dist/utils/token.d.ts +30 -0
- package/dist/utils/token.d.ts.map +1 -0
- package/dist/utils/token.js +39 -0
- package/package.json +85 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useSignUp Hook
|
|
3
|
+
*
|
|
4
|
+
* React hook for signing up a new user.
|
|
5
|
+
*/
|
|
6
|
+
'use client';
|
|
7
|
+
import { useState } from 'react';
|
|
8
|
+
import { z } from 'zod/v4';
|
|
9
|
+
// Zod validates the required fields; .passthrough() preserves the rest.
|
|
10
|
+
// The API returns JSON-serialized User objects (Dates as ISO strings).
|
|
11
|
+
// z.infer output has an index signature incompatible with the concrete User
|
|
12
|
+
// interface, so we extract the validated user via the helper below.
|
|
13
|
+
const SignUpUserSchema = z
|
|
14
|
+
.object({
|
|
15
|
+
id: z.string(),
|
|
16
|
+
email: z.string(),
|
|
17
|
+
name: z.string().nullable().optional(),
|
|
18
|
+
})
|
|
19
|
+
.passthrough();
|
|
20
|
+
/**
|
|
21
|
+
* Narrow Zod-validated API response data to User.
|
|
22
|
+
*
|
|
23
|
+
* The cast is safe because: (1) Zod verified the required fields (id, email),
|
|
24
|
+
* (2) .passthrough() preserves all other properties from the API response,
|
|
25
|
+
* and (3) the API serializes a full User row (Dates become ISO strings in JSON).
|
|
26
|
+
*/
|
|
27
|
+
function toUser(validated) {
|
|
28
|
+
return validated;
|
|
29
|
+
}
|
|
30
|
+
// Validation schemas for sign-up response
|
|
31
|
+
const SignUpErrorResponseSchema = z.object({
|
|
32
|
+
message: z.string().optional(),
|
|
33
|
+
error: z.string().optional(),
|
|
34
|
+
});
|
|
35
|
+
const SignUpSuccessResponseSchema = z.object({
|
|
36
|
+
user: SignUpUserSchema,
|
|
37
|
+
});
|
|
38
|
+
/**
|
|
39
|
+
* Hook to sign up a new user
|
|
40
|
+
*
|
|
41
|
+
* @returns Sign up function, loading state, and error
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```tsx
|
|
45
|
+
* function SignUpForm() {
|
|
46
|
+
* const { signUp, isLoading } = useSignUp()
|
|
47
|
+
*
|
|
48
|
+
* const handleSubmit = async (e: FormEvent) => {
|
|
49
|
+
* e.preventDefault()
|
|
50
|
+
* const result = await signUp({ email, password, name })
|
|
51
|
+
* if (result.success) {
|
|
52
|
+
* router.push('/dashboard')
|
|
53
|
+
* }
|
|
54
|
+
* }
|
|
55
|
+
* }
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export function useSignUp() {
|
|
59
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
60
|
+
const [error, setError] = useState(null);
|
|
61
|
+
const signUp = async (input) => {
|
|
62
|
+
try {
|
|
63
|
+
setIsLoading(true);
|
|
64
|
+
setError(null);
|
|
65
|
+
const response = await fetch('/api/auth/sign-up', {
|
|
66
|
+
method: 'POST',
|
|
67
|
+
headers: {
|
|
68
|
+
'Content-Type': 'application/json',
|
|
69
|
+
},
|
|
70
|
+
credentials: 'include',
|
|
71
|
+
body: JSON.stringify(input),
|
|
72
|
+
});
|
|
73
|
+
const json = await response.json();
|
|
74
|
+
if (!response.ok) {
|
|
75
|
+
const errorData = SignUpErrorResponseSchema.parse(json);
|
|
76
|
+
return {
|
|
77
|
+
success: false,
|
|
78
|
+
error: errorData.message || errorData.error || 'Failed to sign up',
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
const successData = SignUpSuccessResponseSchema.parse(json);
|
|
82
|
+
return {
|
|
83
|
+
success: true,
|
|
84
|
+
// Type assertion through unknown is safe because Zod validation ensures the shape is correct
|
|
85
|
+
// The API returns serialized data, so we cast to expected type
|
|
86
|
+
user: toUser(successData.user),
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
catch (err) {
|
|
90
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
91
|
+
setError(error);
|
|
92
|
+
return {
|
|
93
|
+
success: false,
|
|
94
|
+
error: error.message,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
finally {
|
|
98
|
+
setIsLoading(false);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
return {
|
|
102
|
+
signUp,
|
|
103
|
+
isLoading,
|
|
104
|
+
error,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Security Event Bridge — Connects auth events to the audit trail.
|
|
3
|
+
*
|
|
4
|
+
* Each function wraps an auth operation with structured audit logging
|
|
5
|
+
* via the AuditSystem from @revealui/security. Uses lazy import to
|
|
6
|
+
* avoid circular dependency issues at module load time.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Record a successful login to the audit trail.
|
|
10
|
+
*
|
|
11
|
+
* @param userId - The authenticated user's ID
|
|
12
|
+
* @param ip - Client IP address
|
|
13
|
+
* @param userAgent - Client User-Agent header
|
|
14
|
+
*/
|
|
15
|
+
export declare function auditLoginSuccess(userId: string, ip: string, userAgent: string): Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* Record a failed login attempt to the audit trail.
|
|
18
|
+
*
|
|
19
|
+
* @param email - The email used in the failed attempt
|
|
20
|
+
* @param ip - Client IP address
|
|
21
|
+
* @param userAgent - Client User-Agent header
|
|
22
|
+
* @param reason - Why the login failed (e.g. 'invalid_password', 'account_locked')
|
|
23
|
+
*/
|
|
24
|
+
export declare function auditLoginFailure(email: string, ip: string, userAgent: string, reason: string): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Record a password change to the audit trail.
|
|
27
|
+
*
|
|
28
|
+
* @param userId - The user who changed their password
|
|
29
|
+
* @param ip - Client IP address
|
|
30
|
+
*/
|
|
31
|
+
export declare function auditPasswordChange(userId: string, ip: string): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Record a password reset request to the audit trail.
|
|
34
|
+
*
|
|
35
|
+
* @param email - The email for which a reset was requested
|
|
36
|
+
* @param ip - Client IP address
|
|
37
|
+
*/
|
|
38
|
+
export declare function auditPasswordReset(email: string, ip: string): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* Record MFA being enabled on an account to the audit trail.
|
|
41
|
+
*
|
|
42
|
+
* @param userId - The user who enabled MFA
|
|
43
|
+
* @param ip - Client IP address
|
|
44
|
+
*/
|
|
45
|
+
export declare function auditMfaEnabled(userId: string, ip: string): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Record MFA being disabled on an account to the audit trail.
|
|
48
|
+
*
|
|
49
|
+
* @param userId - The user who disabled MFA
|
|
50
|
+
* @param ip - Client IP address
|
|
51
|
+
*/
|
|
52
|
+
export declare function auditMfaDisabled(userId: string, ip: string): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Record a session revocation to the audit trail.
|
|
55
|
+
*
|
|
56
|
+
* @param userId - The user whose session was revoked
|
|
57
|
+
* @param sessionId - The revoked session's ID
|
|
58
|
+
* @param ip - Client IP address
|
|
59
|
+
*/
|
|
60
|
+
export declare function auditSessionRevoked(userId: string, sessionId: string, ip: string): Promise<void>;
|
|
61
|
+
/**
|
|
62
|
+
* Record an account lockout to the audit trail.
|
|
63
|
+
*
|
|
64
|
+
* @param email - The locked account's email
|
|
65
|
+
* @param ip - Client IP address
|
|
66
|
+
* @param failedAttempts - Number of failed attempts that triggered the lockout
|
|
67
|
+
*/
|
|
68
|
+
export declare function auditAccountLocked(email: string, ip: string, failedAttempts: number): Promise<void>;
|
|
69
|
+
//# sourceMappingURL=audit-bridge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit-bridge.d.ts","sourceRoot":"","sources":["../../src/server/audit-bridge.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAgCH;;;;;;GAMG;AACH,wBAAsB,iBAAiB,CACrC,MAAM,EAAE,MAAM,EACd,EAAE,EAAE,MAAM,EACV,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,IAAI,CAAC,CASf;AAED;;;;;;;GAOG;AACH,wBAAsB,iBAAiB,CACrC,KAAK,EAAE,MAAM,EACb,EAAE,EAAE,MAAM,EACV,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC,CAUf;AAED;;;;;GAKG;AACH,wBAAsB,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CASnF;AAED;;;;;GAKG;AACH,wBAAsB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAUjF;AAED;;;;;GAKG;AACH,wBAAsB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAS/E;AAED;;;;;GAKG;AACH,wBAAsB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAShF;AAED;;;;;;GAMG;AACH,wBAAsB,mBAAmB,CACvC,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,EACjB,EAAE,EAAE,MAAM,GACT,OAAO,CAAC,IAAI,CAAC,CAUf;AAED;;;;;;GAMG;AACH,wBAAsB,kBAAkB,CACtC,KAAK,EAAE,MAAM,EACb,EAAE,EAAE,MAAM,EACV,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC,IAAI,CAAC,CAUf"}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Security Event Bridge — Connects auth events to the audit trail.
|
|
3
|
+
*
|
|
4
|
+
* Each function wraps an auth operation with structured audit logging
|
|
5
|
+
* via the AuditSystem from @revealui/security. Uses lazy import to
|
|
6
|
+
* avoid circular dependency issues at module load time.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Lazily resolve the global audit system from @revealui/security.
|
|
10
|
+
* Returns null if the module cannot be loaded (e.g. in test environments
|
|
11
|
+
* where @revealui/security is not available).
|
|
12
|
+
*/
|
|
13
|
+
async function getAudit() {
|
|
14
|
+
try {
|
|
15
|
+
const { audit } = await import('@revealui/security');
|
|
16
|
+
return audit;
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Internal helper — logs an audit event, silently skipping if the
|
|
24
|
+
* audit system is unavailable.
|
|
25
|
+
*/
|
|
26
|
+
async function logAuditEvent(event) {
|
|
27
|
+
const auditSystem = await getAudit();
|
|
28
|
+
if (!auditSystem) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
await auditSystem.log(event);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Record a successful login to the audit trail.
|
|
35
|
+
*
|
|
36
|
+
* @param userId - The authenticated user's ID
|
|
37
|
+
* @param ip - Client IP address
|
|
38
|
+
* @param userAgent - Client User-Agent header
|
|
39
|
+
*/
|
|
40
|
+
export async function auditLoginSuccess(userId, ip, userAgent) {
|
|
41
|
+
await logAuditEvent({
|
|
42
|
+
type: 'auth.login',
|
|
43
|
+
severity: 'low',
|
|
44
|
+
actor: { id: userId, type: 'user', ip, userAgent },
|
|
45
|
+
action: 'login',
|
|
46
|
+
result: 'success',
|
|
47
|
+
message: 'User logged in successfully',
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Record a failed login attempt to the audit trail.
|
|
52
|
+
*
|
|
53
|
+
* @param email - The email used in the failed attempt
|
|
54
|
+
* @param ip - Client IP address
|
|
55
|
+
* @param userAgent - Client User-Agent header
|
|
56
|
+
* @param reason - Why the login failed (e.g. 'invalid_password', 'account_locked')
|
|
57
|
+
*/
|
|
58
|
+
export async function auditLoginFailure(email, ip, userAgent, reason) {
|
|
59
|
+
await logAuditEvent({
|
|
60
|
+
type: 'auth.failed_login',
|
|
61
|
+
severity: 'medium',
|
|
62
|
+
actor: { id: email, type: 'user', ip, userAgent },
|
|
63
|
+
action: 'login',
|
|
64
|
+
result: 'failure',
|
|
65
|
+
message: `Login failed: ${reason}`,
|
|
66
|
+
metadata: { email, reason },
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Record a password change to the audit trail.
|
|
71
|
+
*
|
|
72
|
+
* @param userId - The user who changed their password
|
|
73
|
+
* @param ip - Client IP address
|
|
74
|
+
*/
|
|
75
|
+
export async function auditPasswordChange(userId, ip) {
|
|
76
|
+
await logAuditEvent({
|
|
77
|
+
type: 'auth.password_change',
|
|
78
|
+
severity: 'medium',
|
|
79
|
+
actor: { id: userId, type: 'user', ip },
|
|
80
|
+
action: 'password_change',
|
|
81
|
+
result: 'success',
|
|
82
|
+
message: 'Password changed',
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Record a password reset request to the audit trail.
|
|
87
|
+
*
|
|
88
|
+
* @param email - The email for which a reset was requested
|
|
89
|
+
* @param ip - Client IP address
|
|
90
|
+
*/
|
|
91
|
+
export async function auditPasswordReset(email, ip) {
|
|
92
|
+
await logAuditEvent({
|
|
93
|
+
type: 'auth.password_reset',
|
|
94
|
+
severity: 'medium',
|
|
95
|
+
actor: { id: email, type: 'user', ip },
|
|
96
|
+
action: 'password_reset',
|
|
97
|
+
result: 'success',
|
|
98
|
+
message: 'Password reset requested',
|
|
99
|
+
metadata: { email },
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Record MFA being enabled on an account to the audit trail.
|
|
104
|
+
*
|
|
105
|
+
* @param userId - The user who enabled MFA
|
|
106
|
+
* @param ip - Client IP address
|
|
107
|
+
*/
|
|
108
|
+
export async function auditMfaEnabled(userId, ip) {
|
|
109
|
+
await logAuditEvent({
|
|
110
|
+
type: 'auth.mfa_enabled',
|
|
111
|
+
severity: 'medium',
|
|
112
|
+
actor: { id: userId, type: 'user', ip },
|
|
113
|
+
action: 'mfa_enabled',
|
|
114
|
+
result: 'success',
|
|
115
|
+
message: 'MFA enabled',
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Record MFA being disabled on an account to the audit trail.
|
|
120
|
+
*
|
|
121
|
+
* @param userId - The user who disabled MFA
|
|
122
|
+
* @param ip - Client IP address
|
|
123
|
+
*/
|
|
124
|
+
export async function auditMfaDisabled(userId, ip) {
|
|
125
|
+
await logAuditEvent({
|
|
126
|
+
type: 'auth.mfa_disabled',
|
|
127
|
+
severity: 'high',
|
|
128
|
+
actor: { id: userId, type: 'user', ip },
|
|
129
|
+
action: 'mfa_disabled',
|
|
130
|
+
result: 'success',
|
|
131
|
+
message: 'MFA disabled',
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Record a session revocation to the audit trail.
|
|
136
|
+
*
|
|
137
|
+
* @param userId - The user whose session was revoked
|
|
138
|
+
* @param sessionId - The revoked session's ID
|
|
139
|
+
* @param ip - Client IP address
|
|
140
|
+
*/
|
|
141
|
+
export async function auditSessionRevoked(userId, sessionId, ip) {
|
|
142
|
+
await logAuditEvent({
|
|
143
|
+
type: 'security.alert',
|
|
144
|
+
severity: 'medium',
|
|
145
|
+
actor: { id: userId, type: 'user', ip },
|
|
146
|
+
action: 'session_revoked',
|
|
147
|
+
result: 'success',
|
|
148
|
+
message: 'Session revoked',
|
|
149
|
+
metadata: { sessionId },
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Record an account lockout to the audit trail.
|
|
154
|
+
*
|
|
155
|
+
* @param email - The locked account's email
|
|
156
|
+
* @param ip - Client IP address
|
|
157
|
+
* @param failedAttempts - Number of failed attempts that triggered the lockout
|
|
158
|
+
*/
|
|
159
|
+
export async function auditAccountLocked(email, ip, failedAttempts) {
|
|
160
|
+
await logAuditEvent({
|
|
161
|
+
type: 'security.alert',
|
|
162
|
+
severity: 'high',
|
|
163
|
+
actor: { id: email, type: 'user', ip },
|
|
164
|
+
action: 'account_locked',
|
|
165
|
+
result: 'failure',
|
|
166
|
+
message: `Account locked after ${String(failedAttempts)} failed attempts`,
|
|
167
|
+
metadata: { email, failedAttempts },
|
|
168
|
+
});
|
|
169
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Authentication Functions (Server-side)
|
|
3
|
+
*
|
|
4
|
+
* Sign in and sign up functionality with password hashing.
|
|
5
|
+
*/
|
|
6
|
+
import type { SignInResult, SignUpResult } from '../types.js';
|
|
7
|
+
/**
|
|
8
|
+
* Sign in with email and password
|
|
9
|
+
*
|
|
10
|
+
* @param email - User email
|
|
11
|
+
* @param password - User password
|
|
12
|
+
* @param options - Additional options (userAgent, ipAddress)
|
|
13
|
+
* @returns Sign in result with user and session token
|
|
14
|
+
*/
|
|
15
|
+
export declare function signIn(email: string, password: string, options?: {
|
|
16
|
+
userAgent?: string;
|
|
17
|
+
ipAddress?: string;
|
|
18
|
+
}): Promise<SignInResult>;
|
|
19
|
+
/**
|
|
20
|
+
* Check if a given email is allowed to sign up.
|
|
21
|
+
*
|
|
22
|
+
* Behavior:
|
|
23
|
+
* - If REVEALUI_SIGNUP_OPEN is 'true', all emails are allowed.
|
|
24
|
+
* - If REVEALUI_SIGNUP_WHITELIST is set (comma-separated emails), only listed emails pass.
|
|
25
|
+
* - If neither env var is set, signups are open (backwards compatible).
|
|
26
|
+
*
|
|
27
|
+
* @param email - Lowercase, trimmed email to check
|
|
28
|
+
* @returns true if signup is allowed
|
|
29
|
+
*/
|
|
30
|
+
export declare function isSignupAllowed(email: string): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Sign up a new user
|
|
33
|
+
*
|
|
34
|
+
* @param email - User email
|
|
35
|
+
* @param password - User password
|
|
36
|
+
* @param name - User name
|
|
37
|
+
* @param options - Additional options
|
|
38
|
+
* @returns Sign up result with user and session token
|
|
39
|
+
*/
|
|
40
|
+
export declare function signUp(email: string, password: string, name: string, options?: {
|
|
41
|
+
userAgent?: string;
|
|
42
|
+
ipAddress?: string;
|
|
43
|
+
tosAcceptedAt?: Date;
|
|
44
|
+
tosVersion?: string;
|
|
45
|
+
}): Promise<SignUpResult>;
|
|
46
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/server/auth.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAQH,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAQ,MAAM,aAAa,CAAC;AASpE;;;;;;;GAOG;AACH,wBAAsB,MAAM,CAC1B,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE;IACR,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,GACA,OAAO,CAAC,YAAY,CAAC,CAuKvB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAiBtD;AAED;;;;;;;;GAQG;AACH,wBAAsB,MAAM,CAC1B,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE;IACR,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,IAAI,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,GACA,OAAO,CAAC,YAAY,CAAC,CAsLvB"}
|