@arch-cadre/auth 0.0.1
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/actions/basic.cjs +46 -0
- package/dist/actions/basic.d.ts +14 -0
- package/dist/actions/basic.mjs +32 -0
- package/dist/actions/email.cjs +209 -0
- package/dist/actions/email.d.ts +7 -0
- package/dist/actions/email.mjs +186 -0
- package/dist/actions/index.cjs +27 -0
- package/dist/actions/index.d.ts +2 -0
- package/dist/actions/index.mjs +2 -0
- package/dist/index.cjs +16 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.mjs +9 -0
- package/dist/intl.d.ts +13 -0
- package/dist/routes.cjs +46 -0
- package/dist/routes.d.ts +2 -0
- package/dist/routes.mjs +48 -0
- package/dist/types.cjs +1 -0
- package/dist/types.d.ts +12 -0
- package/dist/types.mjs +0 -0
- package/dist/ui/forgot-password/components.cjs +91 -0
- package/dist/ui/forgot-password/components.d.ts +2 -0
- package/dist/ui/forgot-password/components.mjs +63 -0
- package/dist/ui/forgot-password/page.cjs +13 -0
- package/dist/ui/forgot-password/page.d.ts +2 -0
- package/dist/ui/forgot-password/page.mjs +5 -0
- package/dist/ui/layout.cjs +39 -0
- package/dist/ui/layout.d.ts +4 -0
- package/dist/ui/layout.mjs +18 -0
- package/dist/ui/reset-password/components.cjs +109 -0
- package/dist/ui/reset-password/components.d.ts +2 -0
- package/dist/ui/reset-password/components.mjs +84 -0
- package/dist/ui/reset-password/page.cjs +29 -0
- package/dist/ui/reset-password/page.d.ts +2 -0
- package/dist/ui/reset-password/page.mjs +21 -0
- package/dist/ui/reset-password/verify-email/components.cjs +106 -0
- package/dist/ui/reset-password/verify-email/components.d.ts +4 -0
- package/dist/ui/reset-password/verify-email/components.mjs +62 -0
- package/dist/ui/reset-password/verify-email/page.cjs +31 -0
- package/dist/ui/reset-password/verify-email/page.d.ts +2 -0
- package/dist/ui/reset-password/verify-email/page.mjs +21 -0
- package/dist/ui/signin/components.cjs +172 -0
- package/dist/ui/signin/components.d.ts +11 -0
- package/dist/ui/signin/components.mjs +134 -0
- package/dist/ui/signin/page.cjs +41 -0
- package/dist/ui/signin/page.d.ts +2 -0
- package/dist/ui/signin/page.mjs +39 -0
- package/dist/ui/signup/components.cjs +193 -0
- package/dist/ui/signup/components.d.ts +11 -0
- package/dist/ui/signup/components.mjs +150 -0
- package/dist/ui/signup/page.cjs +36 -0
- package/dist/ui/signup/page.d.ts +2 -0
- package/dist/ui/signup/page.mjs +34 -0
- package/dist/ui/verify-email/components.cjs +129 -0
- package/dist/ui/verify-email/components.d.ts +4 -0
- package/dist/ui/verify-email/components.mjs +76 -0
- package/dist/ui/verify-email/page.cjs +29 -0
- package/dist/ui/verify-email/page.d.ts +2 -0
- package/dist/ui/verify-email/page.mjs +21 -0
- package/dist/validation.cjs +43 -0
- package/dist/validation.d.ts +97 -0
- package/dist/validation.mjs +37 -0
- package/locales/en/global.json +35 -0
- package/manifest.json +11 -0
- package/package.json +57 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use server";
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.loginAction = loginAction;
|
|
8
|
+
exports.logoutAction = logoutAction;
|
|
9
|
+
exports.signupAction = signupAction;
|
|
10
|
+
var _server = require("@arch-cadre/core/server");
|
|
11
|
+
var _navigation = require("next/navigation");
|
|
12
|
+
async function loginAction(data) {
|
|
13
|
+
const result = await (0, _server.signIn)(data);
|
|
14
|
+
console.log("[LoginAction] SignIn result:", JSON.stringify(result, null, 2));
|
|
15
|
+
if (result.status === "ERROR") {
|
|
16
|
+
return {
|
|
17
|
+
success: false,
|
|
18
|
+
message: result.message
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
if (result.redirect) {
|
|
22
|
+
return (0, _navigation.redirect)(result.redirect);
|
|
23
|
+
}
|
|
24
|
+
if (result.status === "SUCCESS") {
|
|
25
|
+
return (0, _navigation.redirect)("/");
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
success: false,
|
|
29
|
+
message: "Invalid authentication state"
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
async function signupAction(data) {
|
|
33
|
+
try {
|
|
34
|
+
await (0, _server.signUp)(data);
|
|
35
|
+
return (0, _navigation.redirect)("/verify-email");
|
|
36
|
+
} catch (error) {
|
|
37
|
+
return {
|
|
38
|
+
success: false,
|
|
39
|
+
message: error.message || "Failed to create account"
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
async function logoutAction() {
|
|
44
|
+
await (0, _server.signOut)();
|
|
45
|
+
return (0, _navigation.redirect)("/signin");
|
|
46
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { LoginInput, RegisterInput } from "@arch-cadre/core";
|
|
2
|
+
import type { ActionResult } from "../types";
|
|
3
|
+
/**
|
|
4
|
+
* Modern Login Action delegating to Core Auth
|
|
5
|
+
*/
|
|
6
|
+
export declare function loginAction(data: LoginInput): Promise<ActionResult>;
|
|
7
|
+
/**
|
|
8
|
+
* Modern Signup Action delegating to Core Auth
|
|
9
|
+
*/
|
|
10
|
+
export declare function signupAction(data: RegisterInput): Promise<ActionResult>;
|
|
11
|
+
/**
|
|
12
|
+
* Modern Logout Action delegating to Core Auth
|
|
13
|
+
*/
|
|
14
|
+
export declare function logoutAction(): Promise<ActionResult>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use server";
|
|
2
|
+
import { signIn, signOut, signUp } from "@arch-cadre/core/server";
|
|
3
|
+
import { redirect } from "next/navigation";
|
|
4
|
+
export async function loginAction(data) {
|
|
5
|
+
const result = await signIn(data);
|
|
6
|
+
console.log("[LoginAction] SignIn result:", JSON.stringify(result, null, 2));
|
|
7
|
+
if (result.status === "ERROR") {
|
|
8
|
+
return { success: false, message: result.message };
|
|
9
|
+
}
|
|
10
|
+
if (result.redirect) {
|
|
11
|
+
return redirect(result.redirect);
|
|
12
|
+
}
|
|
13
|
+
if (result.status === "SUCCESS") {
|
|
14
|
+
return redirect("/");
|
|
15
|
+
}
|
|
16
|
+
return { success: false, message: "Invalid authentication state" };
|
|
17
|
+
}
|
|
18
|
+
export async function signupAction(data) {
|
|
19
|
+
try {
|
|
20
|
+
await signUp(data);
|
|
21
|
+
return redirect("/verify-email");
|
|
22
|
+
} catch (error) {
|
|
23
|
+
return {
|
|
24
|
+
success: false,
|
|
25
|
+
message: error.message || "Failed to create account"
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export async function logoutAction() {
|
|
30
|
+
await signOut();
|
|
31
|
+
return redirect("/signin");
|
|
32
|
+
}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use server";
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.forgotPasswordAction = forgotPasswordAction;
|
|
8
|
+
exports.resendEmailVerificationCodeAction = resendEmailVerificationCodeAction;
|
|
9
|
+
exports.resetPasswordAction = resetPasswordAction;
|
|
10
|
+
exports.verifyEmailAction = verifyEmailAction;
|
|
11
|
+
exports.verifyPasswordResetEmailAction = verifyPasswordResetEmailAction;
|
|
12
|
+
var _core = require("@arch-cadre/core");
|
|
13
|
+
var _server = require("@arch-cadre/core/server");
|
|
14
|
+
var _navigation = require("next/navigation");
|
|
15
|
+
async function forgotPasswordAction(data) {
|
|
16
|
+
const {
|
|
17
|
+
email
|
|
18
|
+
} = await _core.forgotPasswordSchema.parseAsync(data);
|
|
19
|
+
const user = await (0, _server.getUserFromEmail)(email);
|
|
20
|
+
if (!user) {
|
|
21
|
+
return {
|
|
22
|
+
success: false,
|
|
23
|
+
message: "Not found user with this email"
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
await (0, _server.invalidateUserPasswordResetSessions)(user.id);
|
|
27
|
+
const sessionToken = await (0, _server.generateSessionToken)();
|
|
28
|
+
const session = await (0, _server.createPasswordResetSession)(sessionToken, user.id, user.email);
|
|
29
|
+
await (0, _server.sendPasswordResetEmail)(session.email, session.code);
|
|
30
|
+
await (0, _server.setPasswordResetSessionTokenCookie)(sessionToken, session.expiresAt);
|
|
31
|
+
await _server.eventBus.publish("auth:password-reset:requested", {
|
|
32
|
+
userId: user.id,
|
|
33
|
+
email: user.email
|
|
34
|
+
});
|
|
35
|
+
return (0, _navigation.redirect)("/reset-password/verify-email");
|
|
36
|
+
}
|
|
37
|
+
async function verifyPasswordResetEmailAction(data) {
|
|
38
|
+
const {
|
|
39
|
+
session,
|
|
40
|
+
user
|
|
41
|
+
} = await (0, _server.getCurrentPasswordResetSession)();
|
|
42
|
+
if (!session || !user) {
|
|
43
|
+
return {
|
|
44
|
+
success: false,
|
|
45
|
+
message: "Not authenticated"
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
if (session.emailVerified) {
|
|
49
|
+
return {
|
|
50
|
+
success: false,
|
|
51
|
+
message: "Email already verified"
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
const {
|
|
55
|
+
code
|
|
56
|
+
} = _core.verifyEmailSchema.parse(data);
|
|
57
|
+
if (session.code !== code) {
|
|
58
|
+
return {
|
|
59
|
+
success: false,
|
|
60
|
+
message: "Incorrect code"
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
await (0, _server.setPasswordResetSessionAsEmailVerified)(session.id);
|
|
64
|
+
const security = await (0, _server.checkSecurity)(session, user);
|
|
65
|
+
if (!security.satisfied && security.redirect) {
|
|
66
|
+
return (0, _navigation.redirect)(security.redirect);
|
|
67
|
+
}
|
|
68
|
+
return (0, _navigation.redirect)("/reset-password");
|
|
69
|
+
}
|
|
70
|
+
async function verifyEmailAction(data) {
|
|
71
|
+
const {
|
|
72
|
+
session,
|
|
73
|
+
user
|
|
74
|
+
} = await (0, _server.getCurrentSession)();
|
|
75
|
+
if (!session || !user) {
|
|
76
|
+
return {
|
|
77
|
+
success: false,
|
|
78
|
+
message: "Not authenticated"
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
let verificationRequest = await (0, _server.getUserEmailVerificationRequestFromRequest)();
|
|
82
|
+
if (!verificationRequest) {
|
|
83
|
+
return {
|
|
84
|
+
success: false,
|
|
85
|
+
message: "Verification request not found"
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
const {
|
|
89
|
+
code
|
|
90
|
+
} = _core.verifyEmailSchema.parse(data);
|
|
91
|
+
if (Date.now() >= verificationRequest.expiresAt.getTime()) {
|
|
92
|
+
verificationRequest = await (0, _server.createEmailVerificationRequest)(user.id, verificationRequest.email);
|
|
93
|
+
await (0, _server.sendVerificationEmail)(verificationRequest.email, verificationRequest.code);
|
|
94
|
+
await (0, _server.setEmailVerificationRequestCookie)(verificationRequest);
|
|
95
|
+
return {
|
|
96
|
+
success: false,
|
|
97
|
+
message: "The verification code was expired. We sent another code to your inbox."
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
if (verificationRequest.code !== code) return {
|
|
101
|
+
success: false,
|
|
102
|
+
message: "Incorrect code"
|
|
103
|
+
};
|
|
104
|
+
const interception = await (0, _server.runEmailVerificationValidators)(user.id);
|
|
105
|
+
if (interception) {
|
|
106
|
+
if (interception.status === "CHALLENGE_REQUIRED") {
|
|
107
|
+
return (0, _navigation.redirect)(interception.redirect || "/signin");
|
|
108
|
+
}
|
|
109
|
+
if (interception.status === "ERROR") {
|
|
110
|
+
return {
|
|
111
|
+
success: false,
|
|
112
|
+
message: interception.message
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
await (0, _server.deleteUserEmailVerificationRequest)(user.id);
|
|
117
|
+
await (0, _server.invalidateUserPasswordResetSessions)(user.id);
|
|
118
|
+
await (0, _server.updateUserEmailAndSetEmailAsVerified)(user.id, verificationRequest.email);
|
|
119
|
+
await (0, _server.deleteEmailVerificationRequestCookie)();
|
|
120
|
+
await _server.eventBus.publish("auth:email-verified", {
|
|
121
|
+
userId: user.id,
|
|
122
|
+
email: verificationRequest.email
|
|
123
|
+
});
|
|
124
|
+
return (0, _navigation.redirect)("/");
|
|
125
|
+
}
|
|
126
|
+
async function resendEmailVerificationCodeAction() {
|
|
127
|
+
const {
|
|
128
|
+
session,
|
|
129
|
+
user
|
|
130
|
+
} = await (0, _server.getCurrentSession)();
|
|
131
|
+
if (!session || !user) {
|
|
132
|
+
return {
|
|
133
|
+
success: false,
|
|
134
|
+
message: "Not authenticated"
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
let verificationRequest = await (0, _server.getUserEmailVerificationRequestFromRequest)();
|
|
138
|
+
if (!verificationRequest) {
|
|
139
|
+
if (user.emailVerifiedAt) {
|
|
140
|
+
return {
|
|
141
|
+
success: false,
|
|
142
|
+
message: "Email already verified"
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
verificationRequest = await (0, _server.createEmailVerificationRequest)(user.id, user.email);
|
|
146
|
+
} else {
|
|
147
|
+
verificationRequest = await (0, _server.createEmailVerificationRequest)(user.id, verificationRequest.email);
|
|
148
|
+
}
|
|
149
|
+
await (0, _server.sendVerificationEmail)(verificationRequest.email, verificationRequest.code);
|
|
150
|
+
await (0, _server.setEmailVerificationRequestCookie)(verificationRequest);
|
|
151
|
+
await _server.eventBus.publish("auth:verification-requested", {
|
|
152
|
+
userId: user.id,
|
|
153
|
+
email: verificationRequest.email
|
|
154
|
+
});
|
|
155
|
+
return {
|
|
156
|
+
success: true,
|
|
157
|
+
message: "A new code was sent to your inbox."
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
async function resetPasswordAction(data) {
|
|
161
|
+
const {
|
|
162
|
+
session: passwordResetSession,
|
|
163
|
+
user
|
|
164
|
+
} = await (0, _server.getCurrentPasswordResetSession)();
|
|
165
|
+
if (!passwordResetSession || !user) {
|
|
166
|
+
return {
|
|
167
|
+
success: false,
|
|
168
|
+
message: "Not authenticated"
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
if (!passwordResetSession.emailVerified) {
|
|
172
|
+
return {
|
|
173
|
+
success: false,
|
|
174
|
+
message: "Forbidden"
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
const {
|
|
178
|
+
password
|
|
179
|
+
} = _core.resetPasswordSchema.parse(data);
|
|
180
|
+
if (!(await (0, _server.verifyPasswordStrength)(password))) {
|
|
181
|
+
return {
|
|
182
|
+
success: false,
|
|
183
|
+
message: "Weak password"
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
const interception = await (0, _server.runPasswordResetValidators)(user.id);
|
|
187
|
+
if (interception) {
|
|
188
|
+
if (interception.status === "CHALLENGE_REQUIRED") {
|
|
189
|
+
return (0, _navigation.redirect)(interception.redirect || "/signin");
|
|
190
|
+
}
|
|
191
|
+
if (interception.status === "ERROR") {
|
|
192
|
+
return {
|
|
193
|
+
success: false,
|
|
194
|
+
message: interception.message
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
await (0, _server.invalidateUserPasswordResetSessions)(user.id);
|
|
199
|
+
await (0, _server.invalidateUserSessions)(user.id);
|
|
200
|
+
await (0, _server.updateUserPassword)(user.id, password);
|
|
201
|
+
const sessionToken = await (0, _server.generateSessionToken)();
|
|
202
|
+
const session = await (0, _server.createSession)(sessionToken, user.id, {});
|
|
203
|
+
await (0, _server.setSessionTokenCookie)(sessionToken, session.expiresAt);
|
|
204
|
+
await (0, _server.deletePasswordResetSessionTokenCookie)();
|
|
205
|
+
await _server.eventBus.publish("auth:password-reset:completed", {
|
|
206
|
+
userId: user.id
|
|
207
|
+
});
|
|
208
|
+
return (0, _navigation.redirect)("/");
|
|
209
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ForgotPasswordInput, ResetPasswordInput, VerifyEmailInput } from "@arch-cadre/core";
|
|
2
|
+
import type { ActionResult } from "../types";
|
|
3
|
+
export declare function forgotPasswordAction(data: ForgotPasswordInput): Promise<ActionResult>;
|
|
4
|
+
export declare function verifyPasswordResetEmailAction(data: VerifyEmailInput): Promise<ActionResult>;
|
|
5
|
+
export declare function verifyEmailAction(data: VerifyEmailInput): Promise<ActionResult>;
|
|
6
|
+
export declare function resendEmailVerificationCodeAction(): Promise<ActionResult>;
|
|
7
|
+
export declare function resetPasswordAction(data: ResetPasswordInput): Promise<ActionResult>;
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"use server";
|
|
2
|
+
import {
|
|
3
|
+
forgotPasswordSchema,
|
|
4
|
+
resetPasswordSchema,
|
|
5
|
+
verifyEmailSchema
|
|
6
|
+
} from "@arch-cadre/core";
|
|
7
|
+
import {
|
|
8
|
+
checkSecurity,
|
|
9
|
+
createEmailVerificationRequest,
|
|
10
|
+
createPasswordResetSession,
|
|
11
|
+
createSession,
|
|
12
|
+
deleteEmailVerificationRequestCookie,
|
|
13
|
+
deletePasswordResetSessionTokenCookie,
|
|
14
|
+
deleteUserEmailVerificationRequest,
|
|
15
|
+
eventBus,
|
|
16
|
+
generateSessionToken,
|
|
17
|
+
getCurrentPasswordResetSession,
|
|
18
|
+
getCurrentSession,
|
|
19
|
+
getUserEmailVerificationRequestFromRequest,
|
|
20
|
+
getUserFromEmail,
|
|
21
|
+
invalidateUserPasswordResetSessions,
|
|
22
|
+
invalidateUserSessions,
|
|
23
|
+
runEmailVerificationValidators,
|
|
24
|
+
runPasswordResetValidators,
|
|
25
|
+
sendPasswordResetEmail,
|
|
26
|
+
sendVerificationEmail,
|
|
27
|
+
setEmailVerificationRequestCookie,
|
|
28
|
+
setPasswordResetSessionAsEmailVerified,
|
|
29
|
+
setPasswordResetSessionTokenCookie,
|
|
30
|
+
setSessionTokenCookie,
|
|
31
|
+
updateUserEmailAndSetEmailAsVerified,
|
|
32
|
+
updateUserPassword,
|
|
33
|
+
verifyPasswordStrength
|
|
34
|
+
} from "@arch-cadre/core/server";
|
|
35
|
+
import { redirect } from "next/navigation";
|
|
36
|
+
export async function forgotPasswordAction(data) {
|
|
37
|
+
const { email } = await forgotPasswordSchema.parseAsync(data);
|
|
38
|
+
const user = await getUserFromEmail(email);
|
|
39
|
+
if (!user) {
|
|
40
|
+
return { success: false, message: "Not found user with this email" };
|
|
41
|
+
}
|
|
42
|
+
await invalidateUserPasswordResetSessions(user.id);
|
|
43
|
+
const sessionToken = await generateSessionToken();
|
|
44
|
+
const session = await createPasswordResetSession(
|
|
45
|
+
sessionToken,
|
|
46
|
+
user.id,
|
|
47
|
+
user.email
|
|
48
|
+
);
|
|
49
|
+
await sendPasswordResetEmail(session.email, session.code);
|
|
50
|
+
await setPasswordResetSessionTokenCookie(sessionToken, session.expiresAt);
|
|
51
|
+
await eventBus.publish("auth:password-reset:requested", {
|
|
52
|
+
userId: user.id,
|
|
53
|
+
email: user.email
|
|
54
|
+
});
|
|
55
|
+
return redirect("/reset-password/verify-email");
|
|
56
|
+
}
|
|
57
|
+
export async function verifyPasswordResetEmailAction(data) {
|
|
58
|
+
const { session, user } = await getCurrentPasswordResetSession();
|
|
59
|
+
if (!session || !user) {
|
|
60
|
+
return { success: false, message: "Not authenticated" };
|
|
61
|
+
}
|
|
62
|
+
if (session.emailVerified) {
|
|
63
|
+
return { success: false, message: "Email already verified" };
|
|
64
|
+
}
|
|
65
|
+
const { code } = verifyEmailSchema.parse(data);
|
|
66
|
+
if (session.code !== code) {
|
|
67
|
+
return { success: false, message: "Incorrect code" };
|
|
68
|
+
}
|
|
69
|
+
await setPasswordResetSessionAsEmailVerified(session.id);
|
|
70
|
+
const security = await checkSecurity(session, user);
|
|
71
|
+
if (!security.satisfied && security.redirect) {
|
|
72
|
+
return redirect(security.redirect);
|
|
73
|
+
}
|
|
74
|
+
return redirect("/reset-password");
|
|
75
|
+
}
|
|
76
|
+
export async function verifyEmailAction(data) {
|
|
77
|
+
const { session, user } = await getCurrentSession();
|
|
78
|
+
if (!session || !user) {
|
|
79
|
+
return { success: false, message: "Not authenticated" };
|
|
80
|
+
}
|
|
81
|
+
let verificationRequest = await getUserEmailVerificationRequestFromRequest();
|
|
82
|
+
if (!verificationRequest) {
|
|
83
|
+
return { success: false, message: "Verification request not found" };
|
|
84
|
+
}
|
|
85
|
+
const { code } = verifyEmailSchema.parse(data);
|
|
86
|
+
if (Date.now() >= verificationRequest.expiresAt.getTime()) {
|
|
87
|
+
verificationRequest = await createEmailVerificationRequest(
|
|
88
|
+
user.id,
|
|
89
|
+
verificationRequest.email
|
|
90
|
+
);
|
|
91
|
+
await sendVerificationEmail(
|
|
92
|
+
verificationRequest.email,
|
|
93
|
+
verificationRequest.code
|
|
94
|
+
);
|
|
95
|
+
await setEmailVerificationRequestCookie(verificationRequest);
|
|
96
|
+
return {
|
|
97
|
+
success: false,
|
|
98
|
+
message: "The verification code was expired. We sent another code to your inbox."
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
if (verificationRequest.code !== code)
|
|
102
|
+
return { success: false, message: "Incorrect code" };
|
|
103
|
+
const interception = await runEmailVerificationValidators(user.id);
|
|
104
|
+
if (interception) {
|
|
105
|
+
if (interception.status === "CHALLENGE_REQUIRED") {
|
|
106
|
+
return redirect(interception.redirect || "/signin");
|
|
107
|
+
}
|
|
108
|
+
if (interception.status === "ERROR") {
|
|
109
|
+
return { success: false, message: interception.message };
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
await deleteUserEmailVerificationRequest(user.id);
|
|
113
|
+
await invalidateUserPasswordResetSessions(user.id);
|
|
114
|
+
await updateUserEmailAndSetEmailAsVerified(
|
|
115
|
+
user.id,
|
|
116
|
+
verificationRequest.email
|
|
117
|
+
);
|
|
118
|
+
await deleteEmailVerificationRequestCookie();
|
|
119
|
+
await eventBus.publish("auth:email-verified", {
|
|
120
|
+
userId: user.id,
|
|
121
|
+
email: verificationRequest.email
|
|
122
|
+
});
|
|
123
|
+
return redirect("/");
|
|
124
|
+
}
|
|
125
|
+
export async function resendEmailVerificationCodeAction() {
|
|
126
|
+
const { session, user } = await getCurrentSession();
|
|
127
|
+
if (!session || !user) {
|
|
128
|
+
return { success: false, message: "Not authenticated" };
|
|
129
|
+
}
|
|
130
|
+
let verificationRequest = await getUserEmailVerificationRequestFromRequest();
|
|
131
|
+
if (!verificationRequest) {
|
|
132
|
+
if (user.emailVerifiedAt) {
|
|
133
|
+
return { success: false, message: "Email already verified" };
|
|
134
|
+
}
|
|
135
|
+
verificationRequest = await createEmailVerificationRequest(
|
|
136
|
+
user.id,
|
|
137
|
+
user.email
|
|
138
|
+
);
|
|
139
|
+
} else {
|
|
140
|
+
verificationRequest = await createEmailVerificationRequest(
|
|
141
|
+
user.id,
|
|
142
|
+
verificationRequest.email
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
await sendVerificationEmail(
|
|
146
|
+
verificationRequest.email,
|
|
147
|
+
verificationRequest.code
|
|
148
|
+
);
|
|
149
|
+
await setEmailVerificationRequestCookie(verificationRequest);
|
|
150
|
+
await eventBus.publish("auth:verification-requested", {
|
|
151
|
+
userId: user.id,
|
|
152
|
+
email: verificationRequest.email
|
|
153
|
+
});
|
|
154
|
+
return { success: true, message: "A new code was sent to your inbox." };
|
|
155
|
+
}
|
|
156
|
+
export async function resetPasswordAction(data) {
|
|
157
|
+
const { session: passwordResetSession, user } = await getCurrentPasswordResetSession();
|
|
158
|
+
if (!passwordResetSession || !user) {
|
|
159
|
+
return { success: false, message: "Not authenticated" };
|
|
160
|
+
}
|
|
161
|
+
if (!passwordResetSession.emailVerified) {
|
|
162
|
+
return { success: false, message: "Forbidden" };
|
|
163
|
+
}
|
|
164
|
+
const { password } = resetPasswordSchema.parse(data);
|
|
165
|
+
if (!await verifyPasswordStrength(password)) {
|
|
166
|
+
return { success: false, message: "Weak password" };
|
|
167
|
+
}
|
|
168
|
+
const interception = await runPasswordResetValidators(user.id);
|
|
169
|
+
if (interception) {
|
|
170
|
+
if (interception.status === "CHALLENGE_REQUIRED") {
|
|
171
|
+
return redirect(interception.redirect || "/signin");
|
|
172
|
+
}
|
|
173
|
+
if (interception.status === "ERROR") {
|
|
174
|
+
return { success: false, message: interception.message };
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
await invalidateUserPasswordResetSessions(user.id);
|
|
178
|
+
await invalidateUserSessions(user.id);
|
|
179
|
+
await updateUserPassword(user.id, password);
|
|
180
|
+
const sessionToken = await generateSessionToken();
|
|
181
|
+
const session = await createSession(sessionToken, user.id, {});
|
|
182
|
+
await setSessionTokenCookie(sessionToken, session.expiresAt);
|
|
183
|
+
await deletePasswordResetSessionTokenCookie();
|
|
184
|
+
await eventBus.publish("auth:password-reset:completed", { userId: user.id });
|
|
185
|
+
return redirect("/");
|
|
186
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _basic = require("./basic.cjs");
|
|
7
|
+
Object.keys(_basic).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _basic[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _basic[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
var _email = require("./email.cjs");
|
|
18
|
+
Object.keys(_email).forEach(function (key) {
|
|
19
|
+
if (key === "default" || key === "__esModule") return;
|
|
20
|
+
if (key in exports && exports[key] === _email[key]) return;
|
|
21
|
+
Object.defineProperty(exports, key, {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function () {
|
|
24
|
+
return _email[key];
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
var _manifest = _interopRequireDefault(require("../manifest.json"));
|
|
8
|
+
var _routes = require("./routes.cjs");
|
|
9
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
+
const authModule = {
|
|
11
|
+
manifest: _manifest.default,
|
|
12
|
+
routes: {
|
|
13
|
+
public: _routes.publicRoutes
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
module.exports = authModule;
|
package/dist/index.d.ts
ADDED
package/dist/index.mjs
ADDED
package/dist/intl.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type messages from "../locales/en/global.json";
|
|
2
|
+
|
|
3
|
+
type JsonDataType = typeof messages;
|
|
4
|
+
|
|
5
|
+
// declare global {
|
|
6
|
+
// interface IntlMessages extends JsonDataType {}
|
|
7
|
+
// }
|
|
8
|
+
|
|
9
|
+
declare module "@arch-cadre/intl" {
|
|
10
|
+
export interface IntlMessages extends JsonDataType {}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export {};
|
package/dist/routes.cjs
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.publicRoutes = void 0;
|
|
7
|
+
var _dynamic = _interopRequireDefault(require("next/dynamic"));
|
|
8
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
const AuthLayout = (0, _dynamic.default)(() => Promise.resolve().then(() => require("./ui/layout.cjs")));
|
|
10
|
+
const SignInPage = (0, _dynamic.default)(() => Promise.resolve().then(() => require("./ui/signin/page.cjs")));
|
|
11
|
+
const SignUpPage = (0, _dynamic.default)(() => Promise.resolve().then(() => require("./ui/signup/page.cjs")));
|
|
12
|
+
const ForgotPasswordPage = (0, _dynamic.default)(() => Promise.resolve().then(() => require("./ui/forgot-password/page.cjs")));
|
|
13
|
+
const ResetPasswordPage = (0, _dynamic.default)(() => Promise.resolve().then(() => require("./ui/reset-password/page.cjs")));
|
|
14
|
+
const VerifyEmailPage = (0, _dynamic.default)(() => Promise.resolve().then(() => require("./ui/verify-email/page.cjs")));
|
|
15
|
+
const ResetPasswordVerifyEmailPage = (0, _dynamic.default)(() => Promise.resolve().then(() => require("./ui/reset-password/verify-email/page.cjs")));
|
|
16
|
+
const publicRoutes = exports.publicRoutes = [{
|
|
17
|
+
path: "/signin",
|
|
18
|
+
component: SignInPage,
|
|
19
|
+
layout: AuthLayout,
|
|
20
|
+
auth: false
|
|
21
|
+
}, {
|
|
22
|
+
path: "/signup",
|
|
23
|
+
component: SignUpPage,
|
|
24
|
+
layout: AuthLayout,
|
|
25
|
+
auth: false
|
|
26
|
+
}, {
|
|
27
|
+
path: "/forgot-password",
|
|
28
|
+
component: ForgotPasswordPage,
|
|
29
|
+
layout: AuthLayout,
|
|
30
|
+
auth: false
|
|
31
|
+
}, {
|
|
32
|
+
path: "/reset-password",
|
|
33
|
+
component: ResetPasswordPage,
|
|
34
|
+
layout: AuthLayout,
|
|
35
|
+
auth: false
|
|
36
|
+
}, {
|
|
37
|
+
path: "/verify-email",
|
|
38
|
+
component: VerifyEmailPage,
|
|
39
|
+
layout: AuthLayout,
|
|
40
|
+
auth: false
|
|
41
|
+
}, {
|
|
42
|
+
path: "/reset-password/verify-email",
|
|
43
|
+
component: ResetPasswordVerifyEmailPage,
|
|
44
|
+
layout: AuthLayout,
|
|
45
|
+
auth: false
|
|
46
|
+
}];
|
package/dist/routes.d.ts
ADDED
package/dist/routes.mjs
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import dynamic from "next/dynamic";
|
|
2
|
+
const AuthLayout = dynamic(() => import("./ui/layout.mjs"));
|
|
3
|
+
const SignInPage = dynamic(() => import("./ui/signin/page.mjs"));
|
|
4
|
+
const SignUpPage = dynamic(() => import("./ui/signup/page.mjs"));
|
|
5
|
+
const ForgotPasswordPage = dynamic(() => import("./ui/forgot-password/page.mjs"));
|
|
6
|
+
const ResetPasswordPage = dynamic(() => import("./ui/reset-password/page.mjs"));
|
|
7
|
+
const VerifyEmailPage = dynamic(() => import("./ui/verify-email/page.mjs"));
|
|
8
|
+
const ResetPasswordVerifyEmailPage = dynamic(
|
|
9
|
+
() => import("./ui/reset-password/verify-email/page.mjs")
|
|
10
|
+
);
|
|
11
|
+
export const publicRoutes = [
|
|
12
|
+
{
|
|
13
|
+
path: "/signin",
|
|
14
|
+
component: SignInPage,
|
|
15
|
+
layout: AuthLayout,
|
|
16
|
+
auth: false
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
path: "/signup",
|
|
20
|
+
component: SignUpPage,
|
|
21
|
+
layout: AuthLayout,
|
|
22
|
+
auth: false
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
path: "/forgot-password",
|
|
26
|
+
component: ForgotPasswordPage,
|
|
27
|
+
layout: AuthLayout,
|
|
28
|
+
auth: false
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
path: "/reset-password",
|
|
32
|
+
component: ResetPasswordPage,
|
|
33
|
+
layout: AuthLayout,
|
|
34
|
+
auth: false
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
path: "/verify-email",
|
|
38
|
+
component: VerifyEmailPage,
|
|
39
|
+
layout: AuthLayout,
|
|
40
|
+
auth: false
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
path: "/reset-password/verify-email",
|
|
44
|
+
component: ResetPasswordVerifyEmailPage,
|
|
45
|
+
layout: AuthLayout,
|
|
46
|
+
auth: false
|
|
47
|
+
}
|
|
48
|
+
];
|
package/dist/types.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|