@rpcbase/auth 0.188.0 → 0.190.0
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/api/resend-otp/handler.d.ts.map +1 -1
- package/dist/api/sign-up/handler.d.ts.map +1 -1
- package/dist/components/SignUpForm/index.d.ts.map +1 -1
- package/dist/email-validation/index.d.ts +1 -3
- package/dist/email-validation/index.d.ts.map +1 -1
- package/dist/email-validation/index.js +29 -34
- package/dist/email-validation/index.js.map +1 -1
- package/dist/{handler-B1ZE5nYO.js → handler-BbkBmi2V.js} +4 -14
- package/dist/handler-BbkBmi2V.js.map +1 -0
- package/dist/{handler-C7SfLP4c.js → handler-CjwUMkBv.js} +4 -2
- package/dist/handler-CjwUMkBv.js.map +1 -0
- package/dist/{handler-aS6g_PVg.js → handler-DlaZThWe.js} +6 -6
- package/dist/handler-DlaZThWe.js.map +1 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/routes.js +3 -3
- package/package.json +2 -6
- package/dist/handler-B1ZE5nYO.js.map +0 -1
- package/dist/handler-C7SfLP4c.js.map +0 -1
- package/dist/handler-aS6g_PVg.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../../src/api/resend-otp/handler.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,GAAG,EAAE,UAAU,EAAO,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../../src/api/resend-otp/handler.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,GAAG,EAAE,UAAU,EAAO,MAAM,cAAc,CAAA;AAKnD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAElD,OAAO,KAAK,SAAS,MAAM,SAAS,CAAA;AAGpC,eAAO,MAAM,SAAS,EAAE,UAAU,CAAC,SAAS,CAAC,cAAc,EAAE,SAAS,CAAC,eAAe,EAAE,eAAe,CAkEtG,CAAA;yBAEe,KAAK,GAAG,CAAC,eAAe,CAAC;AAAzC,wBAEC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../../src/api/sign-up/handler.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,GAAG,EAAO,UAAU,EAAE,MAAM,cAAc,CAAA;AAKnD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAElD,OAAO,KAAK,MAAM,MAAM,SAAS,CAAA;AAGjC,eAAO,MAAM,MAAM,EAAE,UAAU,CAAC,MAAM,CAAC,cAAc,EAAE,MAAM,CAAC,eAAe,EAAE,eAAe,
|
|
1
|
+
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../../src/api/sign-up/handler.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,GAAG,EAAO,UAAU,EAAE,MAAM,cAAc,CAAA;AAKnD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAElD,OAAO,KAAK,MAAM,MAAM,SAAS,CAAA;AAGjC,eAAO,MAAM,MAAM,EAAE,UAAU,CAAC,MAAM,CAAC,cAAc,EAAE,MAAM,CAAC,eAAe,EAAE,eAAe,CA6F7F,CAAA;yBAEe,KAAK,GAAG,CAAC,eAAe,CAAC;AAAzC,wBAEC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/SignUpForm/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAW,MAAM,OAAO,CAAA;AAYzC,eAAO,MAAM,UAAU,GAAI,sCAIxB;IACD,QAAQ,EAAE,SAAS,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/SignUpForm/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAW,MAAM,OAAO,CAAA;AAYzC,eAAO,MAAM,UAAU,GAAI,sCAIxB;IACD,QAAQ,EAAE,SAAS,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB,4CAwEA,CAAA"}
|
|
@@ -1,4 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
export declare const DISPOSABLE_EMAIL_CACHE_IDLE_MS: number;
|
|
3
|
-
export declare const isDisposableEmailAddress: (email: unknown) => boolean;
|
|
1
|
+
export * from '@rpcbase/server/email-validation';
|
|
4
2
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/email-validation/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/email-validation/index.ts"],"names":[],"mappings":"AAAA,cAAc,kCAAkC,CAAA"}
|
|
@@ -1,40 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
//#region
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}, DISPOSABLE_EMAIL_CACHE_IDLE_MS);
|
|
16
|
-
cacheEvictionTimer.unref();
|
|
17
|
-
};
|
|
18
|
-
var getDisposableEmailDomains = () => {
|
|
19
|
-
disposableEmailDomains ??= require(mailCheckerModulePath).blacklist();
|
|
20
|
-
scheduleCacheEviction();
|
|
21
|
-
return disposableEmailDomains;
|
|
1
|
+
export * from "@rpcbase/server/email-validation";
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __exportAll = (all, no_symbols) => {
|
|
8
|
+
let target = {};
|
|
9
|
+
for (var name in all) __defProp(target, name, {
|
|
10
|
+
get: all[name],
|
|
11
|
+
enumerable: true
|
|
12
|
+
});
|
|
13
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
14
|
+
return target;
|
|
22
15
|
};
|
|
23
|
-
var
|
|
24
|
-
if (typeof
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
if (disposableEmailDomains.has(domain)) return true;
|
|
31
|
-
const nextDot = domain.indexOf(".");
|
|
32
|
-
if (nextDot === -1) return false;
|
|
33
|
-
domain = domain.slice(nextDot + 1);
|
|
16
|
+
var __copyProps = (to, from, except, desc) => {
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
18
|
+
key = keys[i];
|
|
19
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
20
|
+
get: ((k) => from[k]).bind(null, key),
|
|
21
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
22
|
+
});
|
|
34
23
|
}
|
|
35
|
-
return
|
|
24
|
+
return to;
|
|
36
25
|
};
|
|
26
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
27
|
+
//#endregion
|
|
28
|
+
//#region src/email-validation/index.ts
|
|
29
|
+
var email_validation_exports = /* @__PURE__ */ __exportAll({});
|
|
30
|
+
import * as import__rpcbase_server_email_validation from "@rpcbase/server/email-validation";
|
|
31
|
+
__reExport(email_validation_exports, import__rpcbase_server_email_validation);
|
|
37
32
|
//#endregion
|
|
38
|
-
export {
|
|
33
|
+
export { email_validation_exports as t };
|
|
39
34
|
|
|
40
35
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/email-validation/index.ts"],"sourcesContent":["export * from \"@rpcbase/server/email-validation\"\n"],"mappings":""}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as requestSchema, t as ROUTE } from "./sign-up-Di48rzbG.js";
|
|
2
|
-
import {
|
|
2
|
+
import { t as email_validation_exports } from "./email-validation/index.js";
|
|
3
3
|
import crypto from "crypto";
|
|
4
4
|
import { createProvisionedTenant, models } from "@rpcbase/db";
|
|
5
5
|
import { hashPasswordForStorage, sendEmail } from "@rpcbase/server";
|
|
@@ -14,13 +14,7 @@ var signUp = async (payload, ctx) => {
|
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
16
|
const { email, password, rememberMe: _rememberMe } = parsed.data;
|
|
17
|
-
if (await
|
|
18
|
-
ctx.res.status(400);
|
|
19
|
-
return {
|
|
20
|
-
success: false,
|
|
21
|
-
error: DISPOSABLE_EMAIL_ERROR_CODE
|
|
22
|
-
};
|
|
23
|
-
}
|
|
17
|
+
if (await (0, email_validation_exports.getEmailAddressValidationErrorCode)(email)) return { success: true };
|
|
24
18
|
const User = await models.getGlobal("RBUser", ctx);
|
|
25
19
|
const Tenant = await models.getGlobal("RBTenant", ctx);
|
|
26
20
|
if (await User.findOne({ email })) {
|
|
@@ -87,11 +81,7 @@ var signUp = async (payload, ctx) => {
|
|
|
87
81
|
};
|
|
88
82
|
}
|
|
89
83
|
console.log("created new user", user._id.toString());
|
|
90
|
-
return {
|
|
91
|
-
success: true,
|
|
92
|
-
userId: user._id.toString(),
|
|
93
|
-
tenantId
|
|
94
|
-
};
|
|
84
|
+
return { success: true };
|
|
95
85
|
};
|
|
96
86
|
var handler_default = (api) => {
|
|
97
87
|
api.post(ROUTE, signUp);
|
|
@@ -99,4 +89,4 @@ var handler_default = (api) => {
|
|
|
99
89
|
//#endregion
|
|
100
90
|
export { handler_default as default, signUp };
|
|
101
91
|
|
|
102
|
-
//# sourceMappingURL=handler-
|
|
92
|
+
//# sourceMappingURL=handler-BbkBmi2V.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handler-BbkBmi2V.js","names":["crypto","Api","Ctx","ApiHandler","createProvisionedTenant","models","hashPasswordForStorage","sendEmail","getEmailAddressValidationErrorCode","AuthSessionUser","SignUp","signUp","RequestPayload","ResponsePayload","payload","ctx","Promise","parsed","requestSchema","safeParse","success","res","status","error","email","password","rememberMe","_rememberMe","data","User","getGlobal","Tenant","existingUser","findOne","console","log","hashedPassword","tenantId","randomUUID","emailVerificationCode","randomInt","toString","padStart","emailVerificationExpiresAt","Date","now","user","tenants","tenantRoles","save","to","subject","html","text","err","deleteOne","_id","rollbackErr","name","api","post","ROUTE"],"sources":["../src/api/sign-up/handler.ts"],"sourcesContent":["import crypto from \"crypto\"\n\nimport { Api, Ctx, ApiHandler } from \"@rpcbase/api\"\nimport { createProvisionedTenant, models } from \"@rpcbase/db\"\nimport { hashPasswordForStorage, sendEmail } from \"@rpcbase/server\"\n\nimport { getEmailAddressValidationErrorCode } from \"../../email-validation\"\nimport type { AuthSessionUser } from \"../../types\"\n\nimport * as SignUp from \"./index\"\n\n\nexport const signUp: ApiHandler<SignUp.RequestPayload, SignUp.ResponsePayload, AuthSessionUser> = async(\n payload,\n ctx: Ctx<AuthSessionUser>\n): Promise<SignUp.ResponsePayload> => {\n const parsed = SignUp.requestSchema.safeParse(payload)\n\n if (!parsed.success) {\n ctx.res.status(400)\n return { success: false, error: \"invalid_payload\" }\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { email, password, rememberMe: _rememberMe } = parsed.data\n\n if (await getEmailAddressValidationErrorCode(email)) {\n return { success: true }\n }\n\n const User = await models.getGlobal(\"RBUser\", ctx)\n const Tenant = await models.getGlobal(\"RBTenant\", ctx)\n\n const existingUser = await User.findOne({ email })\n\n if (existingUser) {\n console.log(\"user with email already exists\", email)\n // For security, we don't want to reveal if an email is registered.\n // But for this implementation, we'll make it simple.\n ctx.res.status(409)\n return { success: false, error: \"user_exists\" }\n }\n\n const hashedPassword = await hashPasswordForStorage(password)\n\n const tenantId = crypto.randomUUID()\n\n const emailVerificationCode = crypto.randomInt(0, 1_000_000).toString().padStart(6, \"0\")\n const emailVerificationExpiresAt = new Date(Date.now() + 10 * 60 * 1000)\n\n const user = new User({\n email,\n password: hashedPassword,\n tenants: [tenantId],\n tenantRoles: {\n [tenantId]: [\"owner\"],\n },\n emailVerificationCode,\n emailVerificationExpiresAt,\n })\n await user.save()\n\n try {\n await sendEmail({\n to: email,\n subject: `Verify your email: ${emailVerificationCode}`,\n html: `\n <p>Welcome to rpcbase!</p>\n <p>Your verification code is <strong>${emailVerificationCode}</strong>. It expires in 10 minutes.</p>\n <p>If you didn't request this, you can ignore this message.</p>\n `,\n text: `Welcome to rpcbase! Your verification code is ${emailVerificationCode}. It expires in 10 minutes. If you didn't request this, you can ignore this message.`,\n })\n } catch (err) {\n console.error(\"failed to send sign-up email\", err)\n\n try {\n await User.deleteOne({ _id: user._id })\n } catch (rollbackErr) {\n console.error(\"failed to roll back user after sign-up email failure\", rollbackErr)\n }\n\n ctx.res.status(500)\n return { success: false, error: \"email_delivery_failed\" }\n }\n\n try {\n await createProvisionedTenant(Tenant, {\n tenantId,\n name: email,\n })\n } catch (err) {\n console.error(\"failed to initialize tenant for user\", err)\n try {\n await User.deleteOne({ _id: user._id })\n } catch (rollbackErr) {\n console.error(\"failed to roll back user after tenant initialization failure\", rollbackErr)\n }\n ctx.res.status(500)\n return { success: false, error: \"tenant_initialization_failed\" }\n }\n\n console.log(\"created new user\", user._id.toString())\n\n return { success: true }\n}\n\nexport default (api: Api<AuthSessionUser>) => {\n api.post(SignUp.ROUTE, signUp)\n}\n"],"mappings":";;;;;;AAYA,IAAaW,SAAq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AQX,MAAM,gCAAgC+B,GAAG;EAEjD,IAAI;GACF,MAAMzB,KAAK0B,UAAU,EAAEC,KAAKV,KAAKU,IAAI,CAAC;EACxC,SAASC,aAAa;GACpBvB,QAAQX,MAAM,wDAAwDkC,WAAW;EACnF;EAEA1C,IAAIM,IAAIC,OAAO,GAAG;EAClB,OAAO;GAAEF,SAAS;GAAOG,OAAO;EAAwB;CAC1D;CAEA,IAAI;EACF,MAAMnB,wBAAwB2B,QAAQ;GACpCM;GACAqB,MAAMlC;EACR,CAAC;CACH,SAAS8B,KAAK;EACZpB,QAAQX,MAAM,wCAAwC+B,GAAG;EACzD,IAAI;GACF,MAAMzB,KAAK0B,UAAU,EAAEC,KAAKV,KAAKU,IAAI,CAAC;EACxC,SAASC,aAAa;GACpBvB,QAAQX,MAAM,gEAAgEkC,WAAW;EAC3F;EACA1C,IAAIM,IAAIC,OAAO,GAAG;EAClB,OAAO;GAAEF,SAAS;GAAOG,OAAO;EAA+B;CACjE;CAEAW,QAAQC,IAAI,oBAAoBW,KAAKU,IAAIf,SAAS,CAAC;CAEnD,OAAO,EAAErB,SAAS,KAAK;AACzB;AAEA,IAAA,mBAAgBuC,QAA8B;CAC5CA,IAAIC,KAAKlD,OAAcC,MAAM;AAC/B"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { a as string, i as object, n as boolean } from "./schemas-BgOpQqUv.js";
|
|
2
|
+
import { t as email_validation_exports } from "./email-validation/index.js";
|
|
2
3
|
import crypto from "crypto";
|
|
3
4
|
import { models } from "@rpcbase/db";
|
|
4
5
|
import { sendEmail } from "@rpcbase/server";
|
|
@@ -12,7 +13,6 @@ object({
|
|
|
12
13
|
//#endregion
|
|
13
14
|
//#region src/api/resend-otp/handler.ts
|
|
14
15
|
var resendOtp = async (payload, ctx) => {
|
|
15
|
-
const User = await models.getGlobal("RBUser", ctx);
|
|
16
16
|
const parsed = requestSchema.safeParse(payload);
|
|
17
17
|
if (!parsed.success) {
|
|
18
18
|
ctx.res.status(400);
|
|
@@ -22,6 +22,8 @@ var resendOtp = async (payload, ctx) => {
|
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
24
|
const { email } = parsed.data;
|
|
25
|
+
if (await (0, email_validation_exports.getEmailAddressValidationErrorCode)(email)) return { success: true };
|
|
26
|
+
const User = await models.getGlobal("RBUser", ctx);
|
|
25
27
|
const user = await User.findOne({ email });
|
|
26
28
|
if (!user) {
|
|
27
29
|
ctx.res.status(404);
|
|
@@ -72,4 +74,4 @@ var handler_default = (api) => {
|
|
|
72
74
|
//#endregion
|
|
73
75
|
export { handler_default as default, resendOtp };
|
|
74
76
|
|
|
75
|
-
//# sourceMappingURL=handler-
|
|
77
|
+
//# sourceMappingURL=handler-CjwUMkBv.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handler-CjwUMkBv.js","names":["z","ROUTE","requestSchema","object","email","string","RequestPayload","infer","responseSchema","success","boolean","error","optional","ResponsePayload","crypto","Api","ApiHandler","Ctx","models","sendEmail","getEmailAddressValidationErrorCode","AuthSessionUser","ResendOtp","resendOtp","RequestPayload","ResponsePayload","payload","ctx","Promise","parsed","requestSchema","safeParse","success","res","status","error","email","data","User","getGlobal","user","findOne","emailVerificationCode","randomInt","toString","padStart","emailVerificationExpiresAt","Date","now","save","to","subject","html","text","err","console","updateOne","_id","$unset","releaseErr","api","post","ROUTE"],"sources":["../src/api/resend-otp/index.ts","../src/api/resend-otp/handler.ts"],"sourcesContent":["import { z } from \"zod\"\n\n\nexport const ROUTE = \"/api/rb/auth/resend-otp\"\n\nexport const requestSchema = z.object({\n email: z.string().email(),\n})\n\nexport type RequestPayload = z.infer<typeof requestSchema>\n\nexport const responseSchema = z.object({\n success: z.boolean(),\n error: z.string().optional(),\n})\n\nexport type ResponsePayload = z.infer<typeof responseSchema>\n\n","import crypto from \"crypto\"\n\nimport { Api, ApiHandler, Ctx } from \"@rpcbase/api\"\nimport { models } from \"@rpcbase/db\"\nimport { sendEmail } from \"@rpcbase/server\"\n\nimport { getEmailAddressValidationErrorCode } from \"../../email-validation\"\nimport type { AuthSessionUser } from \"../../types\"\n\nimport * as ResendOtp from \"./index\"\n\n\nexport const resendOtp: ApiHandler<ResendOtp.RequestPayload, ResendOtp.ResponsePayload, AuthSessionUser> = async (\n payload,\n ctx: Ctx<AuthSessionUser>\n): Promise<ResendOtp.ResponsePayload> => {\n const parsed = ResendOtp.requestSchema.safeParse(payload)\n\n if (!parsed.success) {\n ctx.res.status(400)\n return { success: false, error: \"invalid_payload\" }\n }\n\n const { email } = parsed.data\n\n if (await getEmailAddressValidationErrorCode(email)) {\n return { success: true }\n }\n\n const User = await models.getGlobal(\"RBUser\", ctx)\n const user = await User.findOne({ email })\n\n if (!user) {\n // TODO(auth): avoid account enumeration (return a generic success response even when the user doesn't exist)\n ctx.res.status(404)\n return { success: false, error: \"user_not_found\" }\n }\n\n // TODO(auth): add server-side throttling / rate limiting for resend-otp\n const emailVerificationCode = crypto.randomInt(0, 1_000_000).toString().padStart(6, \"0\")\n const emailVerificationExpiresAt = new Date(Date.now() + 10 * 60 * 1000)\n\n user.emailVerificationCode = emailVerificationCode\n user.emailVerificationExpiresAt = emailVerificationExpiresAt\n await user.save()\n\n try {\n await sendEmail({\n to: email,\n subject: `Your verification code: ${emailVerificationCode}`,\n html: `\n <p>Your verification code is <strong>${emailVerificationCode}</strong>. It expires in 10 minutes.</p>\n <p>If you didn't request this, you can ignore this message.</p>\n `,\n text: `Your verification code is ${emailVerificationCode}. It expires in 10 minutes. If you didn't request this, you can ignore this message.`,\n })\n } catch (err) {\n console.error(\"failed to resend otp email\", err)\n\n try {\n await User.updateOne(\n { _id: user._id, emailVerificationCode },\n {\n $unset: {\n emailVerificationCode: \"\",\n emailVerificationExpiresAt: \"\",\n },\n },\n )\n } catch (releaseErr) {\n console.error(\"failed to clear unsent otp\", releaseErr)\n }\n\n ctx.res.status(500)\n return { success: false, error: \"email_delivery_failed\" }\n }\n\n return { success: true }\n}\n\nexport default (api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,8BAA8BmB,GAAG;EAE/C,IAAI;GACF,MAAMhB,KAAKkB,UACT;IAAEC,KAAKjB,KAAKiB;IAAKf;GAAsB,GACvC,EACEgB,QAAQ;IACNhB,uBAAuB;IACvBI,4BAA4B;GAC9B,EACF,CACF;EACF,SAASa,YAAY;GACnBJ,QAAQpB,MAAM,8BAA8BwB,UAAU;EACxD;EAEAhC,IAAIM,IAAIC,OAAO,GAAG;EAClB,OAAO;GAAEF,SAAS;GAAOG,OAAO;EAAwB;CAC1D;CAEA,OAAO,EAAEH,SAAS,KAAK;AACzB;AAEA,IAAA,mBAAgB4B,QAA8B;CAC5CA,IAAIC,KAAKvC,OAAiBC,SAAS;AACrC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { a as string, i as object, n as boolean, r as number } from "./schemas-BgOpQqUv.js";
|
|
2
|
-
import {
|
|
2
|
+
import { t as email_validation_exports } from "./email-validation/index.js";
|
|
3
3
|
import crypto from "crypto";
|
|
4
4
|
import { models } from "@rpcbase/db";
|
|
5
5
|
import { sendEmail } from "@rpcbase/server";
|
|
@@ -36,11 +36,11 @@ var requestPasswordReset = async (payload, ctx) => {
|
|
|
36
36
|
};
|
|
37
37
|
}
|
|
38
38
|
const { email } = parsed.data;
|
|
39
|
-
if (await
|
|
40
|
-
ctx.res.
|
|
39
|
+
if (await (0, email_validation_exports.getEmailAddressValidationErrorCode)(email)) {
|
|
40
|
+
ctx.res.setHeader("Retry-After", String(60));
|
|
41
41
|
return {
|
|
42
|
-
success:
|
|
43
|
-
|
|
42
|
+
success: true,
|
|
43
|
+
retryAfterSeconds: 60
|
|
44
44
|
};
|
|
45
45
|
}
|
|
46
46
|
const User = await models.getGlobal("RBUser", ctx);
|
|
@@ -130,4 +130,4 @@ var handler_default = (api) => {
|
|
|
130
130
|
//#endregion
|
|
131
131
|
export { PASSWORD_RESET_COOLDOWN_SECONDS, handler_default as default, requestPasswordReset };
|
|
132
132
|
|
|
133
|
-
//# sourceMappingURL=handler-
|
|
133
|
+
//# sourceMappingURL=handler-DlaZThWe.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handler-DlaZThWe.js","names":["z","ROUTE","requestSchema","object","email","string","RequestPayload","infer","responseSchema","success","boolean","error","optional","retryAfterSeconds","number","int","positive","ResponsePayload","crypto","Api","ApiHandler","Ctx","models","sendEmail","getEmailAddressValidationErrorCode","AuthSessionUser","RequestPasswordReset","PASSWORD_RESET_COOLDOWN_SECONDS","PASSWORD_RESET_CODE_TTL_SECONDS","maskEmailForLog","email","localRaw","domainRaw","split","local","domain","localPrefix","slice","Math","min","length","localMask","repeat","max","domainTailLength","domainTail","domainMask","requestPasswordReset","RequestPayload","ResponsePayload","payload","ctx","Promise","parsed","requestSchema","safeParse","success","res","status","error","data","setHeader","String","retryAfterSeconds","User","getGlobal","requestedAt","Date","cooldownEligibleExpiresAt","getTime","passwordResetCode","randomInt","toString","padStart","passwordResetCodeExpiresAt","user","findOneAndUpdate","$or","$exists","$lte","$set","$unset","passwordResetToken","passwordResetTokenExpiresAt","returnDocument","existingUser","findOne","_id","console","info","to","subject","html","text","err","releaseResult","updateOne","modifiedCount","removeHeader","releaseErr","api","post","ROUTE"],"sources":["../src/api/request-password-reset/index.ts","../src/api/request-password-reset/handler.ts"],"sourcesContent":["import { z } from \"zod\"\n\n\nexport const ROUTE = \"/api/rb/auth/request-password-reset\"\n\nexport const requestSchema = z.object({\n email: z.string().email(),\n})\n\nexport type RequestPayload = z.infer<typeof requestSchema>\n\nexport const responseSchema = z.object({\n success: z.boolean(),\n error: z.string().optional(),\n retryAfterSeconds: z.number().int().positive().optional(),\n})\n\nexport type ResponsePayload = z.infer<typeof responseSchema>\n","import crypto from \"crypto\"\n\nimport { Api, ApiHandler, Ctx } from \"@rpcbase/api\"\nimport { models } from \"@rpcbase/db\"\nimport { sendEmail } from \"@rpcbase/server\"\n\nimport { getEmailAddressValidationErrorCode } from \"../../email-validation\"\nimport type { AuthSessionUser } from \"../../types\"\n\nimport * as RequestPasswordReset from \"./index\"\n\n\nexport const PASSWORD_RESET_COOLDOWN_SECONDS = 60\nconst PASSWORD_RESET_CODE_TTL_SECONDS = 10 * 60\n\nconst maskEmailForLog = (email: string) => {\n const [localRaw, domainRaw = \"\"] = email.split(\"@\")\n const local = localRaw || \"\"\n const domain = domainRaw || \"\"\n const localPrefix = local.slice(0, Math.min(3, local.length))\n const localMask = \"*\".repeat(Math.max(5, local.length - localPrefix.length))\n\n if (!domain) {\n return `${localPrefix}${localMask}@****`\n }\n\n const domainTailLength = Math.min(7, domain.length)\n const domainTail = domain.slice(-domainTailLength)\n const domainMask = \"*\".repeat(Math.max(4, domain.length - domainTailLength))\n\n return `${localPrefix}${localMask}@${domainMask}${domainTail}`\n}\n\n\nexport const requestPasswordReset: ApiHandler<\n RequestPasswordReset.RequestPayload,\n RequestPasswordReset.ResponsePayload,\n AuthSessionUser\n> = async(\n payload,\n ctx: Ctx<AuthSessionUser>\n): Promise<RequestPasswordReset.ResponsePayload> => {\n const parsed = RequestPasswordReset.requestSchema.safeParse(payload)\n\n if (!parsed.success) {\n ctx.res.status(400)\n return { success: false, error: \"invalid_payload\" }\n }\n\n const { email } = parsed.data\n\n if (await getEmailAddressValidationErrorCode(email)) {\n ctx.res.setHeader(\"Retry-After\", String(PASSWORD_RESET_COOLDOWN_SECONDS))\n return { success: true, retryAfterSeconds: PASSWORD_RESET_COOLDOWN_SECONDS }\n }\n\n const User = await models.getGlobal(\"RBUser\", ctx)\n const requestedAt = new Date()\n const cooldownEligibleExpiresAt = new Date(\n requestedAt.getTime() + (PASSWORD_RESET_CODE_TTL_SECONDS - PASSWORD_RESET_COOLDOWN_SECONDS) * 1000,\n )\n const passwordResetCode = crypto.randomInt(0, 1_000_000).toString().padStart(6, \"0\")\n const passwordResetCodeExpiresAt = new Date(requestedAt.getTime() + PASSWORD_RESET_CODE_TTL_SECONDS * 1000)\n\n const user = await User.findOneAndUpdate(\n {\n email,\n $or: [\n { passwordResetCodeExpiresAt: { $exists: false } },\n { passwordResetCodeExpiresAt: { $lte: cooldownEligibleExpiresAt } },\n ],\n },\n {\n $set: {\n passwordResetCode,\n passwordResetCodeExpiresAt,\n },\n $unset: {\n passwordResetToken: \"\",\n passwordResetTokenExpiresAt: \"\",\n },\n },\n { returnDocument: \"after\" },\n )\n\n ctx.res.setHeader(\"Retry-After\", String(PASSWORD_RESET_COOLDOWN_SECONDS))\n\n if (!user) {\n const existingUser = await User.findOne({ email }, { _id: 1 })\n\n if (!existingUser) {\n try {\n console.info(`sending password reset account notice to email ${maskEmailForLog(email)}`)\n await sendEmail({\n to: email,\n subject: \"No account found for your password reset request\",\n html: `\n <p>Hello,</p>\n <p>You requested a new password reset code for this email address, but unfortunately we couldn't find an account associated with it.</p>\n <p>If you didn't request this, you can ignore this message.</p>\n <p>If you're having trouble accessing your account, please contact support.</p>\n `,\n text: \"Hello, You requested a new password reset code for this email address, but unfortunately we couldn't find an account associated with it. If you didn't request this, you can ignore this message. If you're having trouble accessing your account, please contact support.\",\n })\n } catch (err) {\n console.error(\"failed to send password reset account notice email\", err)\n ctx.res.status(500)\n return { success: false, error: \"email_delivery_failed\" }\n }\n }\n\n return { success: true, retryAfterSeconds: PASSWORD_RESET_COOLDOWN_SECONDS }\n }\n\n try {\n console.info(`sending password reset to email ${maskEmailForLog(email)}`)\n await sendEmail({\n to: email,\n subject: `Your password reset code: ${passwordResetCode}`,\n html: `\n <p>Your password reset code is <strong>${passwordResetCode}</strong>. It expires in 10 minutes.</p>\n <p>If you didn't request this, you can ignore this message.</p>\n `,\n text: `Your password reset code is ${passwordResetCode}. It expires in 10 minutes. If you didn't request this, you can ignore this message.`,\n })\n } catch (err) {\n console.error(\"failed to send password reset email\", err)\n\n try {\n const releaseResult = await User.updateOne(\n { _id: user._id, passwordResetCode },\n {\n $unset: {\n passwordResetCode: \"\",\n passwordResetCodeExpiresAt: \"\",\n },\n },\n )\n if (releaseResult.modifiedCount > 0) {\n ctx.res.removeHeader(\"Retry-After\")\n }\n } catch (releaseErr) {\n console.error(\"failed to release password reset cooldown\", releaseErr)\n }\n\n ctx.res.status(500)\n return { success: false, error: \"email_delivery_failed\" }\n }\n\n return { success: true, retryAfterSeconds: PASSWORD_RESET_COOLDOWN_SECONDS }\n}\n\nexport default (api: Api<AuthSessionUser>) => {\n api.post(RequestPasswordReset.ROUTE, requestPasswordReset)\n}\n"],"mappings":";;;;;;AAGA,IAAaC,QAAQ;AAErB,IAAaC,gBAAgBF,OAAS,EACpCI,OAAOJ,OAAS,CAAC,CAACI,MAAM,EAC1B,CAAC;AAI6BJ,OAAS;CACrCS,SAAST,QAAU;CACnBW,OAAOX,OAAS,CAAC,CAACY,SAAS;CAC3BC,mBAAmBb,OAAS,CAAC,CAACe,IAAI,CAAC,CAACC,SAAS,CAAC,CAACJ,SAAS;AAC1D,CAAC;;;ACHD,IAAae,kCAAkC;AAC/C,IAAMC,kCAAkC;AAExC,IAAMC,mBAAmBC,UAAkB;CACzC,MAAM,CAACC,UAAUC,YAAY,MAAMF,MAAMG,MAAM,GAAG;CAClD,MAAMC,QAAQH,YAAY;CAC1B,MAAMI,SAASH,aAAa;CAC5B,MAAMI,cAAcF,MAAMG,MAAM,GAAGC,KAAKC,IAAI,GAAGL,MAAMM,MAAM,CAAC;CAC5D,MAAMC,YAAY,IAAIC,OAAOJ,KAAKK,IAAI,GAAGT,MAAMM,SAASJ,YAAYI,MAAM,CAAC;CAE3E,IAAI,CAACL,QACH,OAAO,GAAGC,cAAcK,UAAS;CAGnC,MAAMG,mBAAmBN,KAAKC,IAAI,GAAGJ,OAAOK,MAAM;CAClD,MAAMK,aAAaV,OAAOE,MAAM,CAACO,gBAAgB;CAGjD,OAAO,GAAGR,cAAcK,UAAS,GAFd,IAAIC,OAAOJ,KAAKK,IAAI,GAAGR,OAAOK,SAASI,gBAAgB,CAErCE,IAAaD;AACpD;AAGA,IAAaE,uBAIT,OACFG,SACAC,QACkD;CAClD,MAAME,SAAAA,cAA4CE,UAAUL,OAAO;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D;IACJ6D,SAAS;IACTC,MAAM;;;;;;IAMNC,MAAM;GACR,CAAC;EACH,SAASC,KAAK;GACZN,QAAQ7B,MAAM,sDAAsDmC,GAAG;GACvE3C,IAAIM,IAAIC,OAAO,GAAG;GAClB,OAAO;IAAEF,SAAS;IAAOG,OAAO;GAAwB;EAC1D;EAGF,OAAO;GAAEH,SAAS;GAAMO,mBAAAA;EAAmD;CAC7E;CAEA,IAAI;EACFyB,QAAQC,KAAK,mCAAmC5D,gBAAgBC,KAAK,GAAG;EACxE,MAAMP,UAAU;GACdmE,IAAI5D;GACJ6D,SAAS,6BAA6BrB;GACtCsB,MAAM;iDACqCtB,kBAAiB;;;GAG5DuB,MAAM,+BAA+BvB,kBAAiB;EACxD,CAAC;CACH,SAASwB,KAAK;EACZN,QAAQ7B,MAAM,uCAAuCmC,GAAG;EAExD,IAAI;GAUF,KAAIC,MATwB/B,KAAKgC,UAC/B;IAAET,KAAKZ,KAAKY;IAAKjB;GAAkB,GACnC,EACEW,QAAQ;IACNX,mBAAmB;IACnBI,4BAA4B;GAC9B,EACF,CACF,EAAA,CACkBuB,gBAAgB,GAChC9C,IAAIM,IAAIyC,aAAa,aAAa;EAEtC,SAASC,YAAY;GACnBX,QAAQ7B,MAAM,6CAA6CwC,UAAU;EACvE;EAEAhD,IAAIM,IAAIC,OAAO,GAAG;EAClB,OAAO;GAAEF,SAAS;GAAOG,OAAO;EAAwB;CAC1D;CAEA,OAAO;EAAEH,SAAS;EAAMO,mBAAAA;CAAmD;AAC7E;AAEA,IAAA,mBAAgBqC,QAA8B;CAC5CA,IAAIC,KAAK3E,OAA4BqB,oBAAoB;AAC3D"}
|
package/dist/index.js
CHANGED
|
@@ -273,7 +273,7 @@ var SignUpForm = ({ children, className, otpNextPath }) => {
|
|
|
273
273
|
});
|
|
274
274
|
const json = await res.json();
|
|
275
275
|
if (!res.ok) {
|
|
276
|
-
const message = json.error === "user_exists" ? "An account already exists with this email." :
|
|
276
|
+
const message = json.error === "user_exists" ? "An account already exists with this email." : "Sign-up failed. Please try again.";
|
|
277
277
|
methods.setError("root", {
|
|
278
278
|
type: "server",
|
|
279
279
|
message
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["React","Link","useLocation","LINKS_REDIRECTION_MAP","Pathname","AuthLayout","t0","$","_c","sidePanel","t1","children","undefined","location","linkTitle","pathname","title","linkLocation","t2","t3","t4","t5","clsx","AppleSignInButton","t0","$","_c","onPress","className","t1","t2","t3","Symbol","for","t4","useFormContext","EmailInput","t0","$","_c","id","className","placeholder","register","formState","error","errors","email","errorMessage","message","t1","t2","t3","t4","hasUnsafeNextPathChars","value","i","length","code","charCodeAt","sanitizeNextPath","raw","nextPath","trim","startsWith","base","URL","url","origin","pathname","search","hash","ReactNode","useNavigate","useSearchParams","useForm","FormProvider","zodResolver","SubmitHandler","z","requestSchema","sanitizeNextPath","SignInFormValues","input","SignInForm","children","className","navigate","searchParams","methods","defaultValues","email","password","rememberMe","navigationGuard","resolver","onSubmit","data","clearErrors","res","fetch","method","headers","body","JSON","stringify","credentials","json","catch","success","error","ok","message","setError","type","nextPath","get","replace","err","handleSubmit","formState","errors","root","ReactNode","useState","useNavigate","useForm","FormProvider","zodResolver","SubmitHandler","z","requestSchema","SignUpFormValues","input","SignUpForm","children","className","otpNextPath","navigate","serverMessage","setServerMessage","methods","defaultValues","email","password","rememberMe","navigationGuard","resolver","onSubmit","data","clearErrors","res","fetch","method","headers","body","JSON","stringify","credentials","json","ok","message","error","setError","type","success","search","URLSearchParams","set","toString","err","handleSubmit","formState","errors","root","ElementType","useFormContext","RememberMeCheckbox","t0","$","_c","label","as","t1","Component","undefined","register","t2","t3","t4","t5","__iconNode","useState","Eye","EyeOff","useFormContext","PasswordInputProps","id","name","className","placeholder","autoComplete","PasswordInput","t0","$","_c","t1","t2","undefined","showPassword","setShowPassword","register","formState","fieldError","errors","errorMessage","message","inputClassName","t3","t4","Parameters","t5","t6","t7","Symbol","for","_temp","t8","t9","t10","t11","t12","t13","prev","useEffect","useState","clsx","useResendCountdown","t0","t1","$","_c","seconds","undefined","initiallyCountingDown","remaining","setRemaining","isCountingDown","setIsCountingDown","t2","t3","timer","setInterval","prev","clearInterval","t4","nextSeconds","value","restart","minutes","Math","floor","secs","t5","toString","padStart","formatted","canResend","t6","ResendCodeButton","onResend","className","disabled","Promise","isSending","setIsSending","handleClick","isDisabled","showCountdown","useRef","useState","useResendCountdown","DEFAULT_PASSWORD_RESET_COOLDOWN_SECONDS","PasswordResetCodeRequestResult","retryAfterSeconds","PasswordResetCodeRequestError","Error","errorCode","constructor","name","parseRetryAfterSeconds","value","seconds","Number","isFinite","undefined","Math","ceil","requestPasswordResetCode","email","Promise","response","fetch","method","headers","body","JSON","stringify","payload","json","catch","success","error","get","ok","usePasswordResetResend","cooldownSeconds","countdown","isResending","setIsResending","isResendingRef","resend","canResend","current","result","restart","remainingSeconds","remaining","formatted","isCountingDown","Boolean"],"sources":["../src/components/AuthLayout/index.tsx","../src/components/AppleSignInButton/index.tsx","../src/components/EmailInput/index.tsx","../src/utils/sanitizeNextPath.ts","../src/components/SignInForm/index.tsx","../src/components/SignUpForm/index.tsx","../src/components/RememberMeCheckbox/index.tsx","../../../node_modules/lucide-react/dist/esm/shared/src/utils/mergeClasses.mjs","../../../node_modules/lucide-react/dist/esm/shared/src/utils/toKebabCase.mjs","../../../node_modules/lucide-react/dist/esm/shared/src/utils/toCamelCase.mjs","../../../node_modules/lucide-react/dist/esm/shared/src/utils/toPascalCase.mjs","../../../node_modules/lucide-react/dist/esm/defaultAttributes.mjs","../../../node_modules/lucide-react/dist/esm/shared/src/utils/hasA11yProp.mjs","../../../node_modules/lucide-react/dist/esm/context.mjs","../../../node_modules/lucide-react/dist/esm/Icon.mjs","../../../node_modules/lucide-react/dist/esm/createLucideIcon.mjs","../../../node_modules/lucide-react/dist/esm/icons/eye-off.mjs","../../../node_modules/lucide-react/dist/esm/icons/eye.mjs","../src/components/PasswordInput/index.tsx","../src/components/ResendCodeButton/index.tsx","../src/passwordReset.ts"],"sourcesContent":["import * as React from \"react\"\nimport {Link, useLocation } from \"@rpcbase/router\"\n\n\nconst LINKS_REDIRECTION_MAP = {\n \"/auth/sign-in\": {\n \"title\": \"Sign Up\",\n \"location\": \"/auth/sign-up\"\n },\n \"/auth/sign-up\": {\n \"title\": \"Sign In\",\n \"location\": \"/auth/sign-in\"\n },\n \"/auth/logout-success\": {\n \"title\": \"Sign In\",\n \"location\": \"/auth/sign-in\"\n }\n}\n\ntype Pathname = keyof typeof LINKS_REDIRECTION_MAP\n\nexport const AuthLayout = ({\n sidePanel = null,\n children,\n}: {\n sidePanel: React.ReactElement | null\n children: React.ReactNode\n}) => {\n const location = useLocation()\n\n const linkTitle = LINKS_REDIRECTION_MAP[location.pathname as Pathname]?.title\n const linkLocation = LINKS_REDIRECTION_MAP[location.pathname as Pathname]?.location\n\n return (\n <div className=\"container relative flex min-h-dvh flex-col items-center justify-center px-4 py-20 sm:px-6 md:px-8 lg:grid lg:h-dvh lg:w-full lg:max-w-none lg:grid-cols-2 lg:px-0 lg:py-0\">\n {/* Top-right redirection link */}\n {linkTitle && linkLocation ? (\n <Link\n className=\"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0 hover:bg-accent hover:text-accent-foreground h-9 px-4 py-2 absolute right-4 top-4 md:right-8 md:top-8\"\n to={linkLocation}\n >\n {linkTitle}\n </Link>\n ) : null}\n <div className=\"relative hidden h-full flex-col bg-muted p-10 text-white dark:border-r lg:flex\">\n {sidePanel}\n </div>\n <div className=\"mx-auto flex w-full flex-col justify-center gap-6 /*sm:w-[350px]*/\">\n {children}\n </div>\n </div>\n )\n}\n","import clsx from \"clsx\"\n\n\nexport const AppleSignInButton = ({\n onPress,\n className,\n}: {\n onPress: () => void;\n className?: string;\n}) => {\n\n return (\n <button\n onClick={onPress}\n className={clsx(`\n w-full\n bg-black text-white hover:bg-gray-800\n flex items-center justify-center\n px-6 py-2\n rounded-lg\n font-medium\n transition duration-150 ease-in-out\n focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-black\n `, className)}\n >\n <svg\n className=\"w-5 h-5 mr-3\"\n xmlns=\"http://www.w3.org/2000/svg\"\n viewBox=\"0 0 24 24\"\n fill=\"white\"\n >\n <path d=\"M12.152 6.896c-.948 0-2.415-1.078-3.96-1.04-2.04.027-3.91 1.183-4.961 3.014-2.117 3.675-.539 9.103 1.519 12.09 1.013 1.454 2.208 3.09 3.792 3.039 1.52-.065 2.09-.987 3.935-.987 1.831 0 2.35.987 3.96.948 1.637-.026 2.676-1.48 3.676-2.948 1.156-1.688 1.636-3.325 1.662-3.415-.039-.013-3.182-1.221-3.22-4.857-.026-3.04 2.48-4.494 2.597-4.559-1.429-2.09-3.623-2.324-4.39-2.376-2-.156-3.675 1.09-4.61 1.09zM15.53 3.83c.843-1.012 1.4-2.427 1.245-3.83-1.207.052-2.662.805-3.532 1.818-.78.896-1.454 2.338-1.273 3.714 1.338.104 2.715-.688 3.559-1.701\" />\n </svg>\n <span>Continue with Apple</span>\n </button>\n )\n}\n","import {useFormContext} from \"@rpcbase/form\"\n\n\nexport const EmailInput = ({\n id,\n className,\n placeholder,\n}: {\n id: string\n className?: string\n placeholder?: string\n}) => {\n const {register, formState} = useFormContext()\n\n const error = formState.errors.email\n let errorMessage: string | undefined\n if (typeof error === \"string\") {\n errorMessage = error\n } else if (error && typeof error.message === \"string\") {\n errorMessage = error.message\n }\n\n return (\n <>\n <input\n id={id}\n type=\"email\"\n required\n autoComplete=\"email\"\n className={className}\n placeholder={placeholder}\n {...register(\"email\")}\n />\n {errorMessage ? (\n <p className=\"mt-1 -mb-2 text-sm/6 text-red-500\">{errorMessage}</p>\n ) : null}\n </>\n )\n}\n","const hasUnsafeNextPathChars = (value: string) => {\n for (let i = 0; i < value.length; i++) {\n const code = value.charCodeAt(i)\n if (code === 92 || code <= 31 || code === 127) return true\n }\n return false\n}\n\nexport const sanitizeNextPath = (raw: string | null) => {\n if (!raw) return null\n\n const nextPath = raw.trim()\n if (!nextPath) return null\n\n if (!nextPath.startsWith(\"/\") || nextPath.startsWith(\"//\")) {\n return null\n }\n\n if (hasUnsafeNextPathChars(nextPath)) {\n return null\n }\n\n try {\n const base = new URL(\"http://localhost\")\n const url = new URL(nextPath, base)\n if (url.origin !== base.origin) {\n return null\n }\n return `${url.pathname}${url.search}${url.hash}`\n } catch {\n return null\n }\n}\n\n","import { ReactNode } from \"react\"\nimport { useNavigate, useSearchParams } from \"@rpcbase/router\"\nimport { useForm, FormProvider, zodResolver } from \"@rpcbase/form\"\nimport type { SubmitHandler } from \"@rpcbase/form\"\nimport { z } from \"zod\"\n\nimport {requestSchema} from \"../../api/sign-in\"\nimport { sanitizeNextPath } from \"../../utils/sanitizeNextPath\"\n\n\ntype SignInFormValues = z.input<typeof requestSchema>\n\nexport const SignInForm = ({\n children,\n className\n}: {\n children: ReactNode,\n className?: string\n}) => {\n const navigate = useNavigate()\n const [searchParams] = useSearchParams()\n\n const methods = useForm<SignInFormValues>({\n defaultValues: {\n email: \"\",\n password: \"\",\n rememberMe: true,\n },\n navigationGuard: false,\n resolver: zodResolver(requestSchema)\n })\n\n const onSubmit: SubmitHandler<SignInFormValues> = async (data) => {\n methods.clearErrors(\"root\")\n\n try {\n const res = await fetch(\"/api/rb/auth/sign-in\", {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify(data),\n credentials: \"include\",\n })\n\n const json = await res.json().catch(() => null) as { success?: boolean; error?: string } | null\n\n if (!res.ok || !json?.success) {\n const message = json?.error === \"invalid_credentials\"\n ? \"Invalid email or password.\"\n : \"Sign-in failed. Please try again.\"\n methods.setError(\"root\", { type: \"server\", message })\n return\n }\n\n const nextPath = sanitizeNextPath(searchParams.get(\"next\")) ?? \"/\"\n navigate(nextPath, { replace: true })\n } catch (err) {\n methods.setError(\"root\", { type: \"server\", message: \"Network error. Please try again.\" })\n }\n }\n\n return (\n <FormProvider {...methods}>\n <form method=\"post\" noValidate className={className} onSubmit={methods.handleSubmit(onSubmit)}>\n {children}\n {methods.formState.errors.root?.message && (\n <p className=\"mt-2 text-sm text-red-600\" role=\"alert\">\n {methods.formState.errors.root.message}\n </p>\n )}\n </form>\n </FormProvider>\n )\n}\n","import {ReactNode, useState} from \"react\"\nimport { useNavigate } from \"@rpcbase/router\"\nimport { useForm, FormProvider, zodResolver } from \"@rpcbase/form\"\nimport type {SubmitHandler} from \"@rpcbase/form\"\nimport { z } from \"zod\"\n\nimport {requestSchema} from \"../../api/sign-up\"\n\n\ntype SignUpFormValues = z.input<typeof requestSchema>\n\n\nexport const SignUpForm = ({\n children,\n className,\n otpNextPath\n}: {\n children: ReactNode,\n className?: string\n otpNextPath?: string\n}) => {\n\n const navigate = useNavigate()\n\n const [serverMessage, setServerMessage] = useState<string | null>(null)\n const methods = useForm<SignUpFormValues>({\n defaultValues: {\n email: \"\",\n password: \"\",\n rememberMe: true,\n },\n navigationGuard: false,\n resolver: zodResolver(requestSchema)\n })\n\n const onSubmit: SubmitHandler<SignUpFormValues> = async (data) => {\n setServerMessage(null)\n methods.clearErrors(\"root\")\n\n try {\n const res = await fetch(\"/api/rb/auth/sign-up\", {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify(data),\n credentials: \"include\",\n })\n\n const json = await res.json()\n\n if (!res.ok) {\n const message = json.error === \"user_exists\"\n ? \"An account already exists with this email.\"\n : json.error === \"disposable_email\"\n ? \"Disposable email addresses are not allowed.\"\n : \"Sign-up failed. Please try again.\"\n methods.setError(\"root\", { type: \"server\", message })\n return\n }\n\n if (!json.success) {\n methods.setError(\"root\", { type: \"server\", message: \"Sign-up failed. Please try again.\" })\n return\n }\n\n const search = new URLSearchParams({ email: data.email })\n if (otpNextPath) {\n search.set(\"next\", otpNextPath)\n }\n navigate(`/auth/sign-up-otp?${search.toString()}`)\n setServerMessage(\"Account created. Check your inbox to verify your email.\")\n } catch (err) {\n methods.setError(\"root\", { type: \"server\", message: \"Network error. Please try again.\" })\n }\n }\n\n return (\n <FormProvider {...methods}>\n <form method=\"post\" noValidate className={className} onSubmit={methods.handleSubmit(onSubmit)}>\n {children}\n {methods.formState.errors.root?.message && (\n <p className=\"mt-2 text-sm text-red-600\" role=\"alert\">\n {methods.formState.errors.root.message}\n </p>\n )}\n {serverMessage && (\n <p className=\"mt-2 text-sm text-green-700\" role=\"status\">\n {serverMessage}\n </p>\n )}\n </form>\n </FormProvider>\n )\n}\n","import type { ElementType } from \"react\"\nimport {useFormContext} from \"@rpcbase/form\"\n\n\nexport const RememberMeCheckbox = ({\n label,\n as: Component = \"input\"\n}: {\n label: string,\n as?: ElementType\n}) => {\n const {register} = useFormContext()\n\n return (\n <>\n <Component\n id=\"rememberMe\"\n {...register(\"rememberMe\")}\n />\n <label\n htmlFor={\"rememberMe\"}\n className=\"pl-2 block text-sm/6 text-gray-900\"\n >\n {label}\n </label>\n </>\n )\n}\n","/**\n * @license lucide-react v1.22.0 - ISC\n *\n * This source code is licensed under the ISC license.\n * See the LICENSE file in the root directory of this source tree.\n */\n\nconst mergeClasses = (...classes) => classes.filter((className, index, array) => {\n return Boolean(className) && className.trim() !== \"\" && array.indexOf(className) === index;\n}).join(\" \").trim();\n\nexport { mergeClasses };\n//# sourceMappingURL=mergeClasses.mjs.map\n","/**\n * @license lucide-react v1.22.0 - ISC\n *\n * This source code is licensed under the ISC license.\n * See the LICENSE file in the root directory of this source tree.\n */\n\nconst toKebabCase = (string) => string.replace(/([a-z0-9])([A-Z])/g, \"$1-$2\").toLowerCase();\n\nexport { toKebabCase };\n//# sourceMappingURL=toKebabCase.mjs.map\n","/**\n * @license lucide-react v1.22.0 - ISC\n *\n * This source code is licensed under the ISC license.\n * See the LICENSE file in the root directory of this source tree.\n */\n\nconst toCamelCase = (string) => string.replace(\n /^([A-Z])|[\\s-_]+(\\w)/g,\n (match, p1, p2) => p2 ? p2.toUpperCase() : p1.toLowerCase()\n);\n\nexport { toCamelCase };\n//# sourceMappingURL=toCamelCase.mjs.map\n","/**\n * @license lucide-react v1.22.0 - ISC\n *\n * This source code is licensed under the ISC license.\n * See the LICENSE file in the root directory of this source tree.\n */\n\nimport { toCamelCase } from './toCamelCase.mjs';\n\nconst toPascalCase = (string) => {\n const camelCase = toCamelCase(string);\n return camelCase.charAt(0).toUpperCase() + camelCase.slice(1);\n};\n\nexport { toPascalCase };\n//# sourceMappingURL=toPascalCase.mjs.map\n","/**\n * @license lucide-react v1.22.0 - ISC\n *\n * This source code is licensed under the ISC license.\n * See the LICENSE file in the root directory of this source tree.\n */\n\nvar defaultAttributes = {\n xmlns: \"http://www.w3.org/2000/svg\",\n width: 24,\n height: 24,\n viewBox: \"0 0 24 24\",\n fill: \"none\",\n stroke: \"currentColor\",\n strokeWidth: 2,\n strokeLinecap: \"round\",\n strokeLinejoin: \"round\"\n};\n\nexport { defaultAttributes as default };\n//# sourceMappingURL=defaultAttributes.mjs.map\n","/**\n * @license lucide-react v1.22.0 - ISC\n *\n * This source code is licensed under the ISC license.\n * See the LICENSE file in the root directory of this source tree.\n */\n\nconst hasA11yProp = (props) => {\n for (const prop in props) {\n if (prop.startsWith(\"aria-\") || prop === \"role\" || prop === \"title\") {\n return true;\n }\n }\n return false;\n};\n\nexport { hasA11yProp };\n//# sourceMappingURL=hasA11yProp.mjs.map\n","\"use strict\";\n\"use client\";\n/**\n * @license lucide-react v1.22.0 - ISC\n *\n * This source code is licensed under the ISC license.\n * See the LICENSE file in the root directory of this source tree.\n */\n\nimport { createContext, useContext, useMemo, createElement } from 'react';\n\nconst LucideContext = createContext({});\nfunction LucideProvider({\n children,\n size,\n color,\n strokeWidth,\n absoluteStrokeWidth,\n className\n}) {\n const value = useMemo(\n () => ({\n size,\n color,\n strokeWidth,\n absoluteStrokeWidth,\n className\n }),\n [size, color, strokeWidth, absoluteStrokeWidth, className]\n );\n return createElement(LucideContext.Provider, { value }, children);\n}\nconst useLucideContext = () => useContext(LucideContext);\n\nexport { LucideProvider, useLucideContext };\n//# sourceMappingURL=context.mjs.map\n","\"use strict\";\n\"use client\";\n/**\n * @license lucide-react v1.22.0 - ISC\n *\n * This source code is licensed under the ISC license.\n * See the LICENSE file in the root directory of this source tree.\n */\n\nimport { forwardRef, createElement } from 'react';\nimport defaultAttributes from './defaultAttributes.mjs';\nimport { hasA11yProp } from './shared/src/utils/hasA11yProp.mjs';\nimport { mergeClasses } from './shared/src/utils/mergeClasses.mjs';\nimport { useLucideContext } from './context.mjs';\n\nconst Icon = forwardRef(\n ({ color, size, strokeWidth, absoluteStrokeWidth, className = \"\", children, iconNode, ...rest }, ref) => {\n const {\n size: contextSize = 24,\n strokeWidth: contextStrokeWidth = 2,\n absoluteStrokeWidth: contextAbsoluteStrokeWidth = false,\n color: contextColor = \"currentColor\",\n className: contextClass = \"\"\n } = useLucideContext() ?? {};\n const calculatedStrokeWidth = absoluteStrokeWidth ?? contextAbsoluteStrokeWidth ? Number(strokeWidth ?? contextStrokeWidth) * 24 / Number(size ?? contextSize) : strokeWidth ?? contextStrokeWidth;\n return createElement(\n \"svg\",\n {\n ref,\n ...defaultAttributes,\n width: size ?? contextSize ?? defaultAttributes.width,\n height: size ?? contextSize ?? defaultAttributes.height,\n stroke: color ?? contextColor,\n strokeWidth: calculatedStrokeWidth,\n className: mergeClasses(\"lucide\", contextClass, className),\n ...!children && !hasA11yProp(rest) && { \"aria-hidden\": \"true\" },\n ...rest\n },\n [\n ...iconNode.map(([tag, attrs]) => createElement(tag, attrs)),\n ...Array.isArray(children) ? children : [children]\n ]\n );\n }\n);\n\nexport { Icon as default };\n//# sourceMappingURL=Icon.mjs.map\n","/**\n * @license lucide-react v1.22.0 - ISC\n *\n * This source code is licensed under the ISC license.\n * See the LICENSE file in the root directory of this source tree.\n */\n\nimport { forwardRef, createElement } from 'react';\nimport { mergeClasses } from './shared/src/utils/mergeClasses.mjs';\nimport { toKebabCase } from './shared/src/utils/toKebabCase.mjs';\nimport { toPascalCase } from './shared/src/utils/toPascalCase.mjs';\nimport Icon from './Icon.mjs';\n\nconst createLucideIcon = (iconName, iconNode) => {\n const Component = forwardRef(\n ({ className, ...props }, ref) => createElement(Icon, {\n ref,\n iconNode,\n className: mergeClasses(\n `lucide-${toKebabCase(toPascalCase(iconName))}`,\n `lucide-${iconName}`,\n className\n ),\n ...props\n })\n );\n Component.displayName = toPascalCase(iconName);\n return Component;\n};\n\nexport { createLucideIcon as default };\n//# sourceMappingURL=createLucideIcon.mjs.map\n","/**\n * @license lucide-react v1.22.0 - ISC\n *\n * This source code is licensed under the ISC license.\n * See the LICENSE file in the root directory of this source tree.\n */\n\nimport createLucideIcon from '../createLucideIcon.mjs';\n\nconst __iconNode = [\n [\n \"path\",\n {\n d: \"M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49\",\n key: \"ct8e1f\"\n }\n ],\n [\"path\", { d: \"M14.084 14.158a3 3 0 0 1-4.242-4.242\", key: \"151rxh\" }],\n [\n \"path\",\n {\n d: \"M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143\",\n key: \"13bj9a\"\n }\n ],\n [\"path\", { d: \"m2 2 20 20\", key: \"1ooewy\" }]\n];\nconst EyeOff = createLucideIcon(\"eye-off\", __iconNode);\n\nexport { __iconNode, EyeOff as default };\n//# sourceMappingURL=eye-off.mjs.map\n","/**\n * @license lucide-react v1.22.0 - ISC\n *\n * This source code is licensed under the ISC license.\n * See the LICENSE file in the root directory of this source tree.\n */\n\nimport createLucideIcon from '../createLucideIcon.mjs';\n\nconst __iconNode = [\n [\n \"path\",\n {\n d: \"M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0\",\n key: \"1nclc0\"\n }\n ],\n [\"circle\", { cx: \"12\", cy: \"12\", r: \"3\", key: \"1v7zrd\" }]\n];\nconst Eye = createLucideIcon(\"eye\", __iconNode);\n\nexport { __iconNode, Eye as default };\n//# sourceMappingURL=eye.mjs.map\n","import { useState } from \"react\"\nimport { Eye, EyeOff } from \"lucide-react\"\nimport { useFormContext } from \"@rpcbase/form\"\n\n\ntype PasswordInputProps = {\n id: string\n name?: string\n className?: string\n placeholder?: string\n autoComplete?: string\n}\n\nexport const PasswordInput = ({\n id,\n name = \"password\",\n className,\n placeholder,\n autoComplete = \"current-password\",\n}: PasswordInputProps) => {\n const [showPassword, setShowPassword] = useState(false)\n const { register, formState } = useFormContext()\n\n const fieldError = formState.errors[name as keyof typeof formState.errors]\n const errorMessage =\n typeof fieldError === \"string\"\n ? fieldError\n : typeof fieldError?.message === \"string\"\n ? fieldError.message\n : undefined\n\n const inputClassName = className ? `${className} pr-11` : \"pr-11\"\n\n return (\n <>\n <div className=\"relative\">\n <input\n id={id}\n type={showPassword ? \"text\" : \"password\"}\n autoComplete={autoComplete}\n className={inputClassName}\n placeholder={placeholder}\n {...register(name as Parameters<typeof register>[0])}\n />\n <button\n type=\"button\"\n className=\"absolute inset-y-0 right-0 flex items-center pr-3 text-gray-500\"\n onClick={() => setShowPassword((prev) => !prev)}\n aria-label={showPassword ? \"Hide characters\" : \"Show characters\"}\n >\n {showPassword ? (\n <EyeOff className=\"h-5 w-5\" aria-hidden />\n ) : (\n <Eye className=\"h-5 w-5\" aria-hidden />\n )}\n </button>\n </div>\n {errorMessage ? (\n <p className=\"mt-1 -mb-2 text-sm/6 text-red-500\">{errorMessage}</p>\n ) : null}\n </>\n )\n}\n","import {useEffect, useState} from \"react\"\nimport clsx from \"clsx\"\n\n\nexport const useResendCountdown = (seconds = 60, initiallyCountingDown = true) => {\n const [remaining, setRemaining] = useState(seconds)\n const [isCountingDown, setIsCountingDown] = useState(initiallyCountingDown)\n\n useEffect(() => {\n if (!isCountingDown) return\n\n const timer = setInterval(() => {\n setRemaining((prev) => {\n if (prev <= 1) {\n setIsCountingDown(false)\n return seconds\n }\n return prev - 1\n })\n }, 1000)\n\n return () => clearInterval(timer)\n }, [isCountingDown, seconds])\n\n const restart = (nextSeconds?: number) => {\n const value = typeof nextSeconds === \"number\" ? nextSeconds : seconds\n setRemaining(value)\n setIsCountingDown(true)\n }\n\n const minutes = Math.floor(remaining / 60)\n const secs = remaining % 60\n const formatted = `${minutes}:${secs.toString().padStart(2, \"0\")}`\n\n const canResend = !isCountingDown\n\n return {remaining, formatted, isCountingDown, canResend, restart}\n}\n\n\nexport const ResendCodeButton = ({\n seconds = 60,\n onResend,\n className,\n disabled,\n}: {\n seconds?: number\n onResend?: () => Promise<void> | void\n className?: string\n disabled?: boolean\n}) => {\n const [isSending, setIsSending] = useState(false)\n const {formatted, isCountingDown, restart, canResend} = useResendCountdown(seconds)\n\n const handleClick = async () => {\n if (!canResend || isSending || disabled) return\n\n try {\n setIsSending(true)\n if (onResend) {\n await onResend()\n }\n } finally {\n restart()\n setIsSending(false)\n }\n }\n\n const isDisabled = disabled || isCountingDown || isSending\n const showCountdown = isDisabled && (isCountingDown || isSending)\n\n return (\n <span className=\"inline-flex items-center gap-2\">\n <button\n type=\"button\"\n onClick={handleClick}\n disabled={isDisabled}\n aria-label=\"Resend code\"\n className={clsx(\n \"text-sm font-semibold text-sky-600 hover:underline disabled:cursor-not-allowed disabled:text-gray-400\",\n className\n )}\n >\n Resend code\n </button>\n {showCountdown ? (\n <span\n data-testid=\"resend-countdown\"\n className=\"text-sm text-gray-500\"\n aria-live=\"polite\"\n >\n ({formatted})\n </span>\n ) : null}\n </span>\n )\n}\n","import { useRef, useState } from \"react\"\n\nimport { useResendCountdown } from \"./components/ResendCodeButton\"\n\n\nexport const DEFAULT_PASSWORD_RESET_COOLDOWN_SECONDS = 60\n\nexport type PasswordResetCodeRequestResult = {\n retryAfterSeconds: number\n}\n\nexport class PasswordResetCodeRequestError extends Error {\n retryAfterSeconds?: number\n errorCode?: string\n\n constructor(retryAfterSeconds?: number, errorCode?: string) {\n super(\"Unable to request a password reset code\")\n this.name = \"PasswordResetCodeRequestError\"\n this.retryAfterSeconds = retryAfterSeconds\n this.errorCode = errorCode\n }\n}\n\nconst parseRetryAfterSeconds = (value: unknown) => {\n const seconds = typeof value === \"number\" ? value : Number(value)\n if (!Number.isFinite(seconds) || seconds <= 0) return undefined\n return Math.ceil(seconds)\n}\n\nexport const requestPasswordResetCode = async(email: string): Promise<PasswordResetCodeRequestResult> => {\n const response = await fetch(\"/api/rb/auth/request-password-reset\", {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({ email }),\n })\n\n const payload = await response.json().catch(() => null) as {\n success?: unknown\n error?: unknown\n retryAfterSeconds?: unknown\n } | null\n const retryAfterSeconds = parseRetryAfterSeconds(payload?.retryAfterSeconds)\n ?? parseRetryAfterSeconds(response.headers.get(\"Retry-After\"))\n\n if (!response.ok || payload?.success !== true) {\n const errorCode = typeof payload?.error === \"string\" ? payload.error : undefined\n throw new PasswordResetCodeRequestError(retryAfterSeconds, errorCode)\n }\n\n return {\n retryAfterSeconds: retryAfterSeconds ?? DEFAULT_PASSWORD_RESET_COOLDOWN_SECONDS,\n }\n}\n\nexport const usePasswordResetResend = ({\n email,\n cooldownSeconds = DEFAULT_PASSWORD_RESET_COOLDOWN_SECONDS,\n}: {\n email?: string | null\n cooldownSeconds?: number\n}) => {\n const countdown = useResendCountdown(cooldownSeconds)\n const [isResending, setIsResending] = useState(false)\n const isResendingRef = useRef(false)\n\n const resend = async() => {\n if (!email || !countdown.canResend || isResendingRef.current) return null\n\n isResendingRef.current = true\n setIsResending(true)\n\n try {\n const result = await requestPasswordResetCode(email)\n countdown.restart(result.retryAfterSeconds)\n return result\n } catch (error) {\n if (error instanceof PasswordResetCodeRequestError && error.retryAfterSeconds) {\n countdown.restart(error.retryAfterSeconds)\n }\n throw error\n } finally {\n isResendingRef.current = false\n setIsResending(false)\n }\n }\n\n return {\n resend,\n isResending,\n remainingSeconds: countdown.remaining,\n formatted: countdown.formatted,\n isCountingDown: countdown.isCountingDown,\n canResend: Boolean(email) && countdown.canResend && !isResending,\n }\n}\n"],"x_google_ignoreList":[7,8,9,10,11,12,13,14,15,16,17],"mappings":";;;;;;;;;;AAIA,IAAMG,wBAAwB;CAC5B,iBAAiB;EACf,SAAS;EACT,YAAY;CACd;CACA,iBAAiB;EACf,SAAS;EACT,YAAY;CACd;CACA,wBAAwB;EACtB,SAAS;EACT,YAAY;CACd;AACF;AAIA,IAAaE,cAAaC,OAAA;CAAA,MAAAC,IAAAC,EAAA,EAAA;CAAC,MAAA,EAAAC,WAAAC,IAAAC,aAAAL;CACzB,MAAAG,YAAAC,OAAAE,KAAAA,IAAA,OAAAF;CAMA,MAAAG,WAAiBX,YAAY;CAE7B,MAAAY,YAAkBX,sBAAsBU,SAAQE,SAA6B,EAAAC;CAC7E,MAAAC,eAAqBd,sBAAsBU,SAAQE,SAAgC,EAAAF;CAAA,IAAAK;CAAA,IAAAX,EAAA,OAAAU,gBAAAV,EAAA,OAAAO,WAAA;EAK9EI,KAAAJ,aAAAG,eACC,oBAAC,MAAD;GACY,WAAA;GACNA,IAAAA;aAEHH;EAJE,CAAA,IADN;EAOOP,EAAA,KAAAU;EAAAV,EAAA,KAAAO;EAAAP,EAAA,KAAAW;CAAA,OAAAA,KAAAX,EAAA;CAAA,IAAAY;CAAA,IAAAZ,EAAA,OAAAE,WAAA;EACRU,KAAA,oBAAA,OAAA;GAAe,WAAA;aACZV;EACG,CAAA;EAAAF,EAAA,KAAAE;EAAAF,EAAA,KAAAY;CAAA,OAAAA,KAAAZ,EAAA;CAAA,IAAAa;CAAA,IAAAb,EAAA,OAAAI,UAAA;EACNS,KAAA,oBAAA,OAAA;GAAe,WAAA;GACZT;EACG,CAAA;EAAAJ,EAAA,KAAAI;EAAAJ,EAAA,KAAAa;CAAA,OAAAA,KAAA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c","sidePanel","t1","children","undefined","location","linkTitle","pathname","title","linkLocation","t2","t3","t4","t5","clsx","AppleSignInButton","t0","$","_c","onPress","className","t1","t2","t3","Symbol","for","t4","useFormContext","EmailInput","t0","$","_c","id","className","placeholder","register","formState","error","errors","email","errorMessage","message","t1","t2","t3","t4","hasUnsafeNextPathChars","value","i","length","code","charCodeAt","sanitizeNextPath","raw","nextPath","trim","startsWith","base","URL","url","origin","pathname","search","hash","ReactNode","useNavigate","useSearchParams","useForm","FormProvider","zodResolver","SubmitHandler","z","requestSchema","sanitizeNextPath","SignInFormValues","input","SignInForm","children","className","navigate","searchParams","methods","defaultValues","email","password","rememberMe","navigationGuard","resolver","onSubmit","data","clearErrors","res","fetch","method","headers","body","JSON","stringify","credentials","json","catch","success","error","ok","message","setError","type","nextPath","get","replace","err","handleSubmit","formState","errors","root","ReactNode","useState","useNavigate","useForm","FormProvider","zodResolver","SubmitHandler","z","requestSchema","SignUpFormValues","input","SignUpForm","children","className","otpNextPath","navigate","serverMessage","setServerMessage","methods","defaultValues","email","password","rememberMe","navigationGuard","resolver","onSubmit","data","clearErrors","res","fetch","method","headers","body","JSON","stringify","credentials","json","ok","message","error","setError","type","success","search","URLSearchParams","set","toString","err","handleSubmit","formState","errors","root","ElementType","useFormContext","RememberMeCheckbox","t0","$","_c","label","as","t1","Component","undefined","register","t2","t3","t4","t5","__iconNode","useState","Eye","EyeOff","useFormContext","PasswordInputProps","id","name","className","placeholder","autoComplete","PasswordInput","t0","$","_c","t1","t2","undefined","showPassword","setShowPassword","register","formState","fieldError","errors","errorMessage","message","inputClassName","t3","t4","Parameters","t5","t6","t7","Symbol","for","_temp","t8","t9","t10","t11","t12","t13","prev","useEffect","useState","clsx","useResendCountdown","t0","t1","$","_c","seconds","undefined","initiallyCountingDown","remaining","setRemaining","isCountingDown","setIsCountingDown","t2","t3","timer","setInterval","prev","clearInterval","t4","nextSeconds","value","restart","minutes","Math","floor","secs","t5","toString","padStart","formatted","canResend","t6","ResendCodeButton","onResend","className","disabled","Promise","isSending","setIsSending","handleClick","isDisabled","showCountdown","useRef","useState","useResendCountdown","DEFAULT_PASSWORD_RESET_COOLDOWN_SECONDS","PasswordResetCodeRequestResult","retryAfterSeconds","PasswordResetCodeRequestError","Error","errorCode","constructor","name","parseRetryAfterSeconds","value","seconds","Number","isFinite","undefined","Math","ceil","requestPasswordResetCode","email","Promise","response","fetch","method","headers","body","JSON","stringify","payload","json","catch","success","error","get","ok","usePasswordResetResend","cooldownSeconds","countdown","isResending","setIsResending","isResendingRef","resend","canResend","current","result","restart","remainingSeconds","remaining","formatted","isCountingDown","Boolean"],"sources":["../src/components/AuthLayout/index.tsx","../src/components/AppleSignInButton/index.tsx","../src/components/EmailInput/index.tsx","../src/utils/sanitizeNextPath.ts","../src/components/SignInForm/index.tsx","../src/components/SignUpForm/index.tsx","../src/components/RememberMeCheckbox/index.tsx","../../../node_modules/lucide-react/dist/esm/shared/src/utils/mergeClasses.mjs","../../../node_modules/lucide-react/dist/esm/shared/src/utils/toKebabCase.mjs","../../../node_modules/lucide-react/dist/esm/shared/src/utils/toCamelCase.mjs","../../../node_modules/lucide-react/dist/esm/shared/src/utils/toPascalCase.mjs","../../../node_modules/lucide-react/dist/esm/defaultAttributes.mjs","../../../node_modules/lucide-react/dist/esm/shared/src/utils/hasA11yProp.mjs","../../../node_modules/lucide-react/dist/esm/context.mjs","../../../node_modules/lucide-react/dist/esm/Icon.mjs","../../../node_modules/lucide-react/dist/esm/createLucideIcon.mjs","../../../node_modules/lucide-react/dist/esm/icons/eye-off.mjs","../../../node_modules/lucide-react/dist/esm/icons/eye.mjs","../src/components/PasswordInput/index.tsx","../src/components/ResendCodeButton/index.tsx","../src/passwordReset.ts"],"sourcesContent":["import * as React from \"react\"\nimport {Link, useLocation } from \"@rpcbase/router\"\n\n\nconst LINKS_REDIRECTION_MAP = {\n \"/auth/sign-in\": {\n \"title\": \"Sign Up\",\n \"location\": \"/auth/sign-up\"\n },\n \"/auth/sign-up\": {\n \"title\": \"Sign In\",\n \"location\": \"/auth/sign-in\"\n },\n \"/auth/logout-success\": {\n \"title\": \"Sign In\",\n \"location\": \"/auth/sign-in\"\n }\n}\n\ntype Pathname = keyof typeof LINKS_REDIRECTION_MAP\n\nexport const AuthLayout = ({\n sidePanel = null,\n children,\n}: {\n sidePanel: React.ReactElement | null\n children: React.ReactNode\n}) => {\n const location = useLocation()\n\n const linkTitle = LINKS_REDIRECTION_MAP[location.pathname as Pathname]?.title\n const linkLocation = LINKS_REDIRECTION_MAP[location.pathname as Pathname]?.location\n\n return (\n <div className=\"container relative flex min-h-dvh flex-col items-center justify-center px-4 py-20 sm:px-6 md:px-8 lg:grid lg:h-dvh lg:w-full lg:max-w-none lg:grid-cols-2 lg:px-0 lg:py-0\">\n {/* Top-right redirection link */}\n {linkTitle && linkLocation ? (\n <Link\n className=\"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0 hover:bg-accent hover:text-accent-foreground h-9 px-4 py-2 absolute right-4 top-4 md:right-8 md:top-8\"\n to={linkLocation}\n >\n {linkTitle}\n </Link>\n ) : null}\n <div className=\"relative hidden h-full flex-col bg-muted p-10 text-white dark:border-r lg:flex\">\n {sidePanel}\n </div>\n <div className=\"mx-auto flex w-full flex-col justify-center gap-6 /*sm:w-[350px]*/\">\n {children}\n </div>\n </div>\n )\n}\n","import clsx from \"clsx\"\n\n\nexport const AppleSignInButton = ({\n onPress,\n className,\n}: {\n onPress: () => void;\n className?: string;\n}) => {\n\n return (\n <button\n onClick={onPress}\n className={clsx(`\n w-full\n bg-black text-white hover:bg-gray-800\n flex items-center justify-center\n px-6 py-2\n rounded-lg\n font-medium\n transition duration-150 ease-in-out\n focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-black\n `, className)}\n >\n <svg\n className=\"w-5 h-5 mr-3\"\n xmlns=\"http://www.w3.org/2000/svg\"\n viewBox=\"0 0 24 24\"\n fill=\"white\"\n >\n <path d=\"M12.152 6.896c-.948 0-2.415-1.078-3.96-1.04-2.04.027-3.91 1.183-4.961 3.014-2.117 3.675-.539 9.103 1.519 12.09 1.013 1.454 2.208 3.09 3.792 3.039 1.52-.065 2.09-.987 3.935-.987 1.831 0 2.35.987 3.96.948 1.637-.026 2.676-1.48 3.676-2.948 1.156-1.688 1.636-3.325 1.662-3.415-.039-.013-3.182-1.221-3.22-4.857-.026-3.04 2.48-4.494 2.597-4.559-1.429-2.09-3.623-2.324-4.39-2.376-2-.156-3.675 1.09-4.61 1.09zM15.53 3.83c.843-1.012 1.4-2.427 1.245-3.83-1.207.052-2.662.805-3.532 1.818-.78.896-1.454 2.338-1.273 3.714 1.338.104 2.715-.688 3.559-1.701\" />\n </svg>\n <span>Continue with Apple</span>\n </button>\n )\n}\n","import {useFormContext} from \"@rpcbase/form\"\n\n\nexport const EmailInput = ({\n id,\n className,\n placeholder,\n}: {\n id: string\n className?: string\n placeholder?: string\n}) => {\n const {register, formState} = useFormContext()\n\n const error = formState.errors.email\n let errorMessage: string | undefined\n if (typeof error === \"string\") {\n errorMessage = error\n } else if (error && typeof error.message === \"string\") {\n errorMessage = error.message\n }\n\n return (\n <>\n <input\n id={id}\n type=\"email\"\n required\n autoComplete=\"email\"\n className={className}\n placeholder={placeholder}\n {...register(\"email\")}\n />\n {errorMessage ? (\n <p className=\"mt-1 -mb-2 text-sm/6 text-red-500\">{errorMessage}</p>\n ) : null}\n </>\n )\n}\n","const hasUnsafeNextPathChars = (value: string) => {\n for (let i = 0; i < value.length; i++) {\n const code = value.charCodeAt(i)\n if (code === 92 || code <= 31 || code === 127) return true\n }\n return false\n}\n\nexport const sanitizeNextPath = (raw: string | null) => {\n if (!raw) return null\n\n const nextPath = raw.trim()\n if (!nextPath) return null\n\n if (!nextPath.startsWith(\"/\") || nextPath.startsWith(\"//\")) {\n return null\n }\n\n if (hasUnsafeNextPathChars(nextPath)) {\n return null\n }\n\n try {\n const base = new URL(\"http://localhost\")\n const url = new URL(nextPath, base)\n if (url.origin !== base.origin) {\n return null\n }\n return `${url.pathname}${url.search}${url.hash}`\n } catch {\n return null\n }\n}\n\n","import { ReactNode } from \"react\"\nimport { useNavigate, useSearchParams } from \"@rpcbase/router\"\nimport { useForm, FormProvider, zodResolver } from \"@rpcbase/form\"\nimport type { SubmitHandler } from \"@rpcbase/form\"\nimport { z } from \"zod\"\n\nimport {requestSchema} from \"../../api/sign-in\"\nimport { sanitizeNextPath } from \"../../utils/sanitizeNextPath\"\n\n\ntype SignInFormValues = z.input<typeof requestSchema>\n\nexport const SignInForm = ({\n children,\n className\n}: {\n children: ReactNode,\n className?: string\n}) => {\n const navigate = useNavigate()\n const [searchParams] = useSearchParams()\n\n const methods = useForm<SignInFormValues>({\n defaultValues: {\n email: \"\",\n password: \"\",\n rememberMe: true,\n },\n navigationGuard: false,\n resolver: zodResolver(requestSchema)\n })\n\n const onSubmit: SubmitHandler<SignInFormValues> = async (data) => {\n methods.clearErrors(\"root\")\n\n try {\n const res = await fetch(\"/api/rb/auth/sign-in\", {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify(data),\n credentials: \"include\",\n })\n\n const json = await res.json().catch(() => null) as { success?: boolean; error?: string } | null\n\n if (!res.ok || !json?.success) {\n const message = json?.error === \"invalid_credentials\"\n ? \"Invalid email or password.\"\n : \"Sign-in failed. Please try again.\"\n methods.setError(\"root\", { type: \"server\", message })\n return\n }\n\n const nextPath = sanitizeNextPath(searchParams.get(\"next\")) ?? \"/\"\n navigate(nextPath, { replace: true })\n } catch (err) {\n methods.setError(\"root\", { type: \"server\", message: \"Network error. Please try again.\" })\n }\n }\n\n return (\n <FormProvider {...methods}>\n <form method=\"post\" noValidate className={className} onSubmit={methods.handleSubmit(onSubmit)}>\n {children}\n {methods.formState.errors.root?.message && (\n <p className=\"mt-2 text-sm text-red-600\" role=\"alert\">\n {methods.formState.errors.root.message}\n </p>\n )}\n </form>\n </FormProvider>\n )\n}\n","import {ReactNode, useState} from \"react\"\nimport { useNavigate } from \"@rpcbase/router\"\nimport { useForm, FormProvider, zodResolver } from \"@rpcbase/form\"\nimport type {SubmitHandler} from \"@rpcbase/form\"\nimport { z } from \"zod\"\n\nimport {requestSchema} from \"../../api/sign-up\"\n\n\ntype SignUpFormValues = z.input<typeof requestSchema>\n\n\nexport const SignUpForm = ({\n children,\n className,\n otpNextPath\n}: {\n children: ReactNode,\n className?: string\n otpNextPath?: string\n}) => {\n\n const navigate = useNavigate()\n\n const [serverMessage, setServerMessage] = useState<string | null>(null)\n const methods = useForm<SignUpFormValues>({\n defaultValues: {\n email: \"\",\n password: \"\",\n rememberMe: true,\n },\n navigationGuard: false,\n resolver: zodResolver(requestSchema)\n })\n\n const onSubmit: SubmitHandler<SignUpFormValues> = async (data) => {\n setServerMessage(null)\n methods.clearErrors(\"root\")\n\n try {\n const res = await fetch(\"/api/rb/auth/sign-up\", {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify(data),\n credentials: \"include\",\n })\n\n const json = await res.json()\n\n if (!res.ok) {\n const message = json.error === \"user_exists\"\n ? \"An account already exists with this email.\"\n : \"Sign-up failed. Please try again.\"\n methods.setError(\"root\", { type: \"server\", message })\n return\n }\n\n if (!json.success) {\n methods.setError(\"root\", { type: \"server\", message: \"Sign-up failed. Please try again.\" })\n return\n }\n\n const search = new URLSearchParams({ email: data.email })\n if (otpNextPath) {\n search.set(\"next\", otpNextPath)\n }\n navigate(`/auth/sign-up-otp?${search.toString()}`)\n setServerMessage(\"Account created. Check your inbox to verify your email.\")\n } catch (err) {\n methods.setError(\"root\", { type: \"server\", message: \"Network error. Please try again.\" })\n }\n }\n\n return (\n <FormProvider {...methods}>\n <form method=\"post\" noValidate className={className} onSubmit={methods.handleSubmit(onSubmit)}>\n {children}\n {methods.formState.errors.root?.message && (\n <p className=\"mt-2 text-sm text-red-600\" role=\"alert\">\n {methods.formState.errors.root.message}\n </p>\n )}\n {serverMessage && (\n <p className=\"mt-2 text-sm text-green-700\" role=\"status\">\n {serverMessage}\n </p>\n )}\n </form>\n </FormProvider>\n )\n}\n","import type { ElementType } from \"react\"\nimport {useFormContext} from \"@rpcbase/form\"\n\n\nexport const RememberMeCheckbox = ({\n label,\n as: Component = \"input\"\n}: {\n label: string,\n as?: ElementType\n}) => {\n const {register} = useFormContext()\n\n return (\n <>\n <Component\n id=\"rememberMe\"\n {...register(\"rememberMe\")}\n />\n <label\n htmlFor={\"rememberMe\"}\n className=\"pl-2 block text-sm/6 text-gray-900\"\n >\n {label}\n </label>\n </>\n )\n}\n","/**\n * @license lucide-react v1.22.0 - ISC\n *\n * This source code is licensed under the ISC license.\n * See the LICENSE file in the root directory of this source tree.\n */\n\nconst mergeClasses = (...classes) => classes.filter((className, index, array) => {\n return Boolean(className) && className.trim() !== \"\" && array.indexOf(className) === index;\n}).join(\" \").trim();\n\nexport { mergeClasses };\n//# sourceMappingURL=mergeClasses.mjs.map\n","/**\n * @license lucide-react v1.22.0 - ISC\n *\n * This source code is licensed under the ISC license.\n * See the LICENSE file in the root directory of this source tree.\n */\n\nconst toKebabCase = (string) => string.replace(/([a-z0-9])([A-Z])/g, \"$1-$2\").toLowerCase();\n\nexport { toKebabCase };\n//# sourceMappingURL=toKebabCase.mjs.map\n","/**\n * @license lucide-react v1.22.0 - ISC\n *\n * This source code is licensed under the ISC license.\n * See the LICENSE file in the root directory of this source tree.\n */\n\nconst toCamelCase = (string) => string.replace(\n /^([A-Z])|[\\s-_]+(\\w)/g,\n (match, p1, p2) => p2 ? p2.toUpperCase() : p1.toLowerCase()\n);\n\nexport { toCamelCase };\n//# sourceMappingURL=toCamelCase.mjs.map\n","/**\n * @license lucide-react v1.22.0 - ISC\n *\n * This source code is licensed under the ISC license.\n * See the LICENSE file in the root directory of this source tree.\n */\n\nimport { toCamelCase } from './toCamelCase.mjs';\n\nconst toPascalCase = (string) => {\n const camelCase = toCamelCase(string);\n return camelCase.charAt(0).toUpperCase() + camelCase.slice(1);\n};\n\nexport { toPascalCase };\n//# sourceMappingURL=toPascalCase.mjs.map\n","/**\n * @license lucide-react v1.22.0 - ISC\n *\n * This source code is licensed under the ISC license.\n * See the LICENSE file in the root directory of this source tree.\n */\n\nvar defaultAttributes = {\n xmlns: \"http://www.w3.org/2000/svg\",\n width: 24,\n height: 24,\n viewBox: \"0 0 24 24\",\n fill: \"none\",\n stroke: \"currentColor\",\n strokeWidth: 2,\n strokeLinecap: \"round\",\n strokeLinejoin: \"round\"\n};\n\nexport { defaultAttributes as default };\n//# sourceMappingURL=defaultAttributes.mjs.map\n","/**\n * @license lucide-react v1.22.0 - ISC\n *\n * This source code is licensed under the ISC license.\n * See the LICENSE file in the root directory of this source tree.\n */\n\nconst hasA11yProp = (props) => {\n for (const prop in props) {\n if (prop.startsWith(\"aria-\") || prop === \"role\" || prop === \"title\") {\n return true;\n }\n }\n return false;\n};\n\nexport { hasA11yProp };\n//# sourceMappingURL=hasA11yProp.mjs.map\n","\"use strict\";\n\"use client\";\n/**\n * @license lucide-react v1.22.0 - ISC\n *\n * This source code is licensed under the ISC license.\n * See the LICENSE file in the root directory of this source tree.\n */\n\nimport { createContext, useContext, useMemo, createElement } from 'react';\n\nconst LucideContext = createContext({});\nfunction LucideProvider({\n children,\n size,\n color,\n strokeWidth,\n absoluteStrokeWidth,\n className\n}) {\n const value = useMemo(\n () => ({\n size,\n color,\n strokeWidth,\n absoluteStrokeWidth,\n className\n }),\n [size, color, strokeWidth, absoluteStrokeWidth, className]\n );\n return createElement(LucideContext.Provider, { value }, children);\n}\nconst useLucideContext = () => useContext(LucideContext);\n\nexport { LucideProvider, useLucideContext };\n//# sourceMappingURL=context.mjs.map\n","\"use strict\";\n\"use client\";\n/**\n * @license lucide-react v1.22.0 - ISC\n *\n * This source code is licensed under the ISC license.\n * See the LICENSE file in the root directory of this source tree.\n */\n\nimport { forwardRef, createElement } from 'react';\nimport defaultAttributes from './defaultAttributes.mjs';\nimport { hasA11yProp } from './shared/src/utils/hasA11yProp.mjs';\nimport { mergeClasses } from './shared/src/utils/mergeClasses.mjs';\nimport { useLucideContext } from './context.mjs';\n\nconst Icon = forwardRef(\n ({ color, size, strokeWidth, absoluteStrokeWidth, className = \"\", children, iconNode, ...rest }, ref) => {\n const {\n size: contextSize = 24,\n strokeWidth: contextStrokeWidth = 2,\n absoluteStrokeWidth: contextAbsoluteStrokeWidth = false,\n color: contextColor = \"currentColor\",\n className: contextClass = \"\"\n } = useLucideContext() ?? {};\n const calculatedStrokeWidth = absoluteStrokeWidth ?? contextAbsoluteStrokeWidth ? Number(strokeWidth ?? contextStrokeWidth) * 24 / Number(size ?? contextSize) : strokeWidth ?? contextStrokeWidth;\n return createElement(\n \"svg\",\n {\n ref,\n ...defaultAttributes,\n width: size ?? contextSize ?? defaultAttributes.width,\n height: size ?? contextSize ?? defaultAttributes.height,\n stroke: color ?? contextColor,\n strokeWidth: calculatedStrokeWidth,\n className: mergeClasses(\"lucide\", contextClass, className),\n ...!children && !hasA11yProp(rest) && { \"aria-hidden\": \"true\" },\n ...rest\n },\n [\n ...iconNode.map(([tag, attrs]) => createElement(tag, attrs)),\n ...Array.isArray(children) ? children : [children]\n ]\n );\n }\n);\n\nexport { Icon as default };\n//# sourceMappingURL=Icon.mjs.map\n","/**\n * @license lucide-react v1.22.0 - ISC\n *\n * This source code is licensed under the ISC license.\n * See the LICENSE file in the root directory of this source tree.\n */\n\nimport { forwardRef, createElement } from 'react';\nimport { mergeClasses } from './shared/src/utils/mergeClasses.mjs';\nimport { toKebabCase } from './shared/src/utils/toKebabCase.mjs';\nimport { toPascalCase } from './shared/src/utils/toPascalCase.mjs';\nimport Icon from './Icon.mjs';\n\nconst createLucideIcon = (iconName, iconNode) => {\n const Component = forwardRef(\n ({ className, ...props }, ref) => createElement(Icon, {\n ref,\n iconNode,\n className: mergeClasses(\n `lucide-${toKebabCase(toPascalCase(iconName))}`,\n `lucide-${iconName}`,\n className\n ),\n ...props\n })\n );\n Component.displayName = toPascalCase(iconName);\n return Component;\n};\n\nexport { createLucideIcon as default };\n//# sourceMappingURL=createLucideIcon.mjs.map\n","/**\n * @license lucide-react v1.22.0 - ISC\n *\n * This source code is licensed under the ISC license.\n * See the LICENSE file in the root directory of this source tree.\n */\n\nimport createLucideIcon from '../createLucideIcon.mjs';\n\nconst __iconNode = [\n [\n \"path\",\n {\n d: \"M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49\",\n key: \"ct8e1f\"\n }\n ],\n [\"path\", { d: \"M14.084 14.158a3 3 0 0 1-4.242-4.242\", key: \"151rxh\" }],\n [\n \"path\",\n {\n d: \"M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143\",\n key: \"13bj9a\"\n }\n ],\n [\"path\", { d: \"m2 2 20 20\", key: \"1ooewy\" }]\n];\nconst EyeOff = createLucideIcon(\"eye-off\", __iconNode);\n\nexport { __iconNode, EyeOff as default };\n//# sourceMappingURL=eye-off.mjs.map\n","/**\n * @license lucide-react v1.22.0 - ISC\n *\n * This source code is licensed under the ISC license.\n * See the LICENSE file in the root directory of this source tree.\n */\n\nimport createLucideIcon from '../createLucideIcon.mjs';\n\nconst __iconNode = [\n [\n \"path\",\n {\n d: \"M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0\",\n key: \"1nclc0\"\n }\n ],\n [\"circle\", { cx: \"12\", cy: \"12\", r: \"3\", key: \"1v7zrd\" }]\n];\nconst Eye = createLucideIcon(\"eye\", __iconNode);\n\nexport { __iconNode, Eye as default };\n//# sourceMappingURL=eye.mjs.map\n","import { useState } from \"react\"\nimport { Eye, EyeOff } from \"lucide-react\"\nimport { useFormContext } from \"@rpcbase/form\"\n\n\ntype PasswordInputProps = {\n id: string\n name?: string\n className?: string\n placeholder?: string\n autoComplete?: string\n}\n\nexport const PasswordInput = ({\n id,\n name = \"password\",\n className,\n placeholder,\n autoComplete = \"current-password\",\n}: PasswordInputProps) => {\n const [showPassword, setShowPassword] = useState(false)\n const { register, formState } = useFormContext()\n\n const fieldError = formState.errors[name as keyof typeof formState.errors]\n const errorMessage =\n typeof fieldError === \"string\"\n ? fieldError\n : typeof fieldError?.message === \"string\"\n ? fieldError.message\n : undefined\n\n const inputClassName = className ? `${className} pr-11` : \"pr-11\"\n\n return (\n <>\n <div className=\"relative\">\n <input\n id={id}\n type={showPassword ? \"text\" : \"password\"}\n autoComplete={autoComplete}\n className={inputClassName}\n placeholder={placeholder}\n {...register(name as Parameters<typeof register>[0])}\n />\n <button\n type=\"button\"\n className=\"absolute inset-y-0 right-0 flex items-center pr-3 text-gray-500\"\n onClick={() => setShowPassword((prev) => !prev)}\n aria-label={showPassword ? \"Hide characters\" : \"Show characters\"}\n >\n {showPassword ? (\n <EyeOff className=\"h-5 w-5\" aria-hidden />\n ) : (\n <Eye className=\"h-5 w-5\" aria-hidden />\n )}\n </button>\n </div>\n {errorMessage ? (\n <p className=\"mt-1 -mb-2 text-sm/6 text-red-500\">{errorMessage}</p>\n ) : null}\n </>\n )\n}\n","import {useEffect, useState} from \"react\"\nimport clsx from \"clsx\"\n\n\nexport const useResendCountdown = (seconds = 60, initiallyCountingDown = true) => {\n const [remaining, setRemaining] = useState(seconds)\n const [isCountingDown, setIsCountingDown] = useState(initiallyCountingDown)\n\n useEffect(() => {\n if (!isCountingDown) return\n\n const timer = setInterval(() => {\n setRemaining((prev) => {\n if (prev <= 1) {\n setIsCountingDown(false)\n return seconds\n }\n return prev - 1\n })\n }, 1000)\n\n return () => clearInterval(timer)\n }, [isCountingDown, seconds])\n\n const restart = (nextSeconds?: number) => {\n const value = typeof nextSeconds === \"number\" ? nextSeconds : seconds\n setRemaining(value)\n setIsCountingDown(true)\n }\n\n const minutes = Math.floor(remaining / 60)\n const secs = remaining % 60\n const formatted = `${minutes}:${secs.toString().padStart(2, \"0\")}`\n\n const canResend = !isCountingDown\n\n return {remaining, formatted, isCountingDown, canResend, restart}\n}\n\n\nexport const ResendCodeButton = ({\n seconds = 60,\n onResend,\n className,\n disabled,\n}: {\n seconds?: number\n onResend?: () => Promise<void> | void\n className?: string\n disabled?: boolean\n}) => {\n const [isSending, setIsSending] = useState(false)\n const {formatted, isCountingDown, restart, canResend} = useResendCountdown(seconds)\n\n const handleClick = async () => {\n if (!canResend || isSending || disabled) return\n\n try {\n setIsSending(true)\n if (onResend) {\n await onResend()\n }\n } finally {\n restart()\n setIsSending(false)\n }\n }\n\n const isDisabled = disabled || isCountingDown || isSending\n const showCountdown = isDisabled && (isCountingDown || isSending)\n\n return (\n <span className=\"inline-flex items-center gap-2\">\n <button\n type=\"button\"\n onClick={handleClick}\n disabled={isDisabled}\n aria-label=\"Resend code\"\n className={clsx(\n \"text-sm font-semibold text-sky-600 hover:underline disabled:cursor-not-allowed disabled:text-gray-400\",\n className\n )}\n >\n Resend code\n </button>\n {showCountdown ? (\n <span\n data-testid=\"resend-countdown\"\n className=\"text-sm text-gray-500\"\n aria-live=\"polite\"\n >\n ({formatted})\n </span>\n ) : null}\n </span>\n )\n}\n","import { useRef, useState } from \"react\"\n\nimport { useResendCountdown } from \"./components/ResendCodeButton\"\n\n\nexport const DEFAULT_PASSWORD_RESET_COOLDOWN_SECONDS = 60\n\nexport type PasswordResetCodeRequestResult = {\n retryAfterSeconds: number\n}\n\nexport class PasswordResetCodeRequestError extends Error {\n retryAfterSeconds?: number\n errorCode?: string\n\n constructor(retryAfterSeconds?: number, errorCode?: string) {\n super(\"Unable to request a password reset code\")\n this.name = \"PasswordResetCodeRequestError\"\n this.retryAfterSeconds = retryAfterSeconds\n this.errorCode = errorCode\n }\n}\n\nconst parseRetryAfterSeconds = (value: unknown) => {\n const seconds = typeof value === \"number\" ? value : Number(value)\n if (!Number.isFinite(seconds) || seconds <= 0) return undefined\n return Math.ceil(seconds)\n}\n\nexport const requestPasswordResetCode = async(email: string): Promise<PasswordResetCodeRequestResult> => {\n const response = await fetch(\"/api/rb/auth/request-password-reset\", {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({ email }),\n })\n\n const payload = await response.json().catch(() => null) as {\n success?: unknown\n error?: unknown\n retryAfterSeconds?: unknown\n } | null\n const retryAfterSeconds = parseRetryAfterSeconds(payload?.retryAfterSeconds)\n ?? parseRetryAfterSeconds(response.headers.get(\"Retry-After\"))\n\n if (!response.ok || payload?.success !== true) {\n const errorCode = typeof payload?.error === \"string\" ? payload.error : undefined\n throw new PasswordResetCodeRequestError(retryAfterSeconds, errorCode)\n }\n\n return {\n retryAfterSeconds: retryAfterSeconds ?? DEFAULT_PASSWORD_RESET_COOLDOWN_SECONDS,\n }\n}\n\nexport const usePasswordResetResend = ({\n email,\n cooldownSeconds = DEFAULT_PASSWORD_RESET_COOLDOWN_SECONDS,\n}: {\n email?: string | null\n cooldownSeconds?: number\n}) => {\n const countdown = useResendCountdown(cooldownSeconds)\n const [isResending, setIsResending] = useState(false)\n const isResendingRef = useRef(false)\n\n const resend = async() => {\n if (!email || !countdown.canResend || isResendingRef.current) return null\n\n isResendingRef.current = true\n setIsResending(true)\n\n try {\n const result = await requestPasswordResetCode(email)\n countdown.restart(result.retryAfterSeconds)\n return result\n } catch (error) {\n if (error instanceof PasswordResetCodeRequestError && error.retryAfterSeconds) {\n countdown.restart(error.retryAfterSeconds)\n }\n throw error\n } finally {\n isResendingRef.current = false\n setIsResending(false)\n }\n }\n\n return {\n resend,\n isResending,\n remainingSeconds: countdown.remaining,\n formatted: countdown.formatted,\n isCountingDown: countdown.isCountingDown,\n canResend: Boolean(email) && countdown.canResend && !isResending,\n }\n}\n"],"x_google_ignoreList":[7,8,9,10,11,12,13,14,15,16,17],"mappings":";;;;;;;;;;AAIA,IAAMG,wBAAwB;CAC5B,iBAAiB;EACf,SA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,QAAQI,QAAQjB,KAAAA,CACH;CAGtE,OAAO,EACLX,mBAAmBA,qBAAAA,GACrB;AACF;AAEA,IAAa+B,0BAA0B,EACrChB,OACAiB,kBAAAA,SAII;CACJ,MAAMC,YAAYpC,mBAAmBmC,eAAe;CACpD,MAAM,CAACE,aAAaC,kBAAkBvC,SAAS,KAAK;CACpD,MAAMwC,iBAAiBzC,OAAO,KAAK;CAEnC,MAAM0C,SAAS,YAAW;EACxB,IAAI,CAACtB,SAAS,CAACkB,UAAUK,aAAaF,eAAeG,SAAS,OAAO;EAErEH,eAAeG,UAAU;EACzBJ,eAAe,IAAI;EAEnB,IAAI;GACF,MAAMK,SAAS,MAAM1B,yBAAyBC,KAAK;GACnDkB,UAAUQ,QAAQD,OAAOxC,iBAAiB;GAC1C,OAAOwC;EACT,SAASZ,OAAO;GACd,IAAIA,iBAAiB3B,iCAAiC2B,MAAM5B,mBAC1DiC,UAAUQ,QAAQb,MAAM5B,iBAAiB;GAE3C,MAAM4B;EACR,UAAU;GACRQ,eAAeG,UAAU;GACzBJ,eAAe,KAAK;EACtB;CACF;CAEA,OAAO;EACLE;EACAH;EACAQ,kBAAkBT,UAAUU;EAC5BC,WAAWX,UAAUW;EACrBC,gBAAgBZ,UAAUY;EAC1BP,WAAWQ,QAAQ/B,KAAK,KAAKkB,UAAUK,aAAa,CAACJ;CACvD;AACF"}
|
package/dist/routes.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
//#region src/routes.ts
|
|
2
2
|
var routes = Object.entries({ .../* #__PURE__ */ Object.assign({
|
|
3
3
|
"./api/me/handler.ts": () => import("./handler-W_XZ0lnx.js"),
|
|
4
|
-
"./api/request-password-reset/handler.ts": () => import("./handler-
|
|
5
|
-
"./api/resend-otp/handler.ts": () => import("./handler-
|
|
4
|
+
"./api/request-password-reset/handler.ts": () => import("./handler-DlaZThWe.js"),
|
|
5
|
+
"./api/resend-otp/handler.ts": () => import("./handler-CjwUMkBv.js"),
|
|
6
6
|
"./api/set-active-account/handler.ts": () => import("./handler-J2FOxq-2.js"),
|
|
7
7
|
"./api/set-new-password/handler.ts": () => import("./handler-DoyR_l2O.js"),
|
|
8
8
|
"./api/sign-in/handler.ts": () => import("./handler-DH9FPTNh.js"),
|
|
9
9
|
"./api/sign-out/handler.ts": () => import("./handler-DQvdRpG2.js"),
|
|
10
|
-
"./api/sign-up/handler.ts": () => import("./handler-
|
|
10
|
+
"./api/sign-up/handler.ts": () => import("./handler-BbkBmi2V.js"),
|
|
11
11
|
"./api/verify-otp/handler.ts": () => import("./handler-DAKI9QOQ.js"),
|
|
12
12
|
"./api/verify-password-reset-otp/handler.ts": () => import("./handler-DAfIloZR.js")
|
|
13
13
|
}) }).reduce((acc, [path, mod]) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rpcbase/auth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.190.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -96,9 +96,6 @@
|
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
},
|
|
99
|
-
"dependencies": {
|
|
100
|
-
"mailchecker": "6.0.21"
|
|
101
|
-
},
|
|
102
99
|
"peerDependencies": {
|
|
103
100
|
"@rpcbase/api": "*",
|
|
104
101
|
"@rpcbase/db": "*",
|
|
@@ -106,6 +103,5 @@
|
|
|
106
103
|
"@rpcbase/router": "*",
|
|
107
104
|
"@rpcbase/server": "*",
|
|
108
105
|
"clsx": "*"
|
|
109
|
-
}
|
|
110
|
-
"devDependencies": {}
|
|
106
|
+
}
|
|
111
107
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"handler-B1ZE5nYO.js","names":["crypto","Api","Ctx","ApiHandler","createProvisionedTenant","models","hashPasswordForStorage","sendEmail","DISPOSABLE_EMAIL_ERROR_CODE","isDisposableEmailAddress","AuthSessionUser","SignUp","signUp","RequestPayload","ResponsePayload","payload","ctx","Promise","parsed","requestSchema","safeParse","success","res","status","error","email","password","rememberMe","_rememberMe","data","User","getGlobal","Tenant","existingUser","findOne","console","log","hashedPassword","tenantId","randomUUID","emailVerificationCode","randomInt","toString","padStart","emailVerificationExpiresAt","Date","now","user","tenants","tenantRoles","save","to","subject","html","text","err","deleteOne","_id","rollbackErr","name","userId","api","post","ROUTE"],"sources":["../src/api/sign-up/handler.ts"],"sourcesContent":["import crypto from \"crypto\"\n\nimport { Api, Ctx, ApiHandler } from \"@rpcbase/api\"\nimport { createProvisionedTenant, models } from \"@rpcbase/db\"\nimport { hashPasswordForStorage, sendEmail } from \"@rpcbase/server\"\n\nimport { DISPOSABLE_EMAIL_ERROR_CODE, isDisposableEmailAddress } from \"../../email-validation\"\nimport type { AuthSessionUser } from \"../../types\"\n\nimport * as SignUp from \"./index\"\n\n\nexport const signUp: ApiHandler<SignUp.RequestPayload, SignUp.ResponsePayload, AuthSessionUser> = async(\n payload,\n ctx: Ctx<AuthSessionUser>\n): Promise<SignUp.ResponsePayload> => {\n const parsed = SignUp.requestSchema.safeParse(payload)\n\n if (!parsed.success) {\n ctx.res.status(400)\n return { success: false, error: \"invalid_payload\" }\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { email, password, rememberMe: _rememberMe } = parsed.data\n\n if (await isDisposableEmailAddress(email)) {\n ctx.res.status(400)\n return { success: false, error: DISPOSABLE_EMAIL_ERROR_CODE }\n }\n\n const User = await models.getGlobal(\"RBUser\", ctx)\n const Tenant = await models.getGlobal(\"RBTenant\", ctx)\n\n const existingUser = await User.findOne({ email })\n\n if (existingUser) {\n console.log(\"user with email already exists\", email)\n // For security, we don't want to reveal if an email is registered.\n // But for this implementation, we'll make it simple.\n ctx.res.status(409)\n return { success: false, error: \"user_exists\" }\n }\n\n const hashedPassword = await hashPasswordForStorage(password)\n\n const tenantId = crypto.randomUUID()\n\n const emailVerificationCode = crypto.randomInt(0, 1_000_000).toString().padStart(6, \"0\")\n const emailVerificationExpiresAt = new Date(Date.now() + 10 * 60 * 1000)\n\n const user = new User({\n email,\n password: hashedPassword,\n tenants: [tenantId],\n tenantRoles: {\n [tenantId]: [\"owner\"],\n },\n emailVerificationCode,\n emailVerificationExpiresAt,\n })\n await user.save()\n\n try {\n await sendEmail({\n to: email,\n subject: `Verify your email: ${emailVerificationCode}`,\n html: `\n <p>Welcome to rpcbase!</p>\n <p>Your verification code is <strong>${emailVerificationCode}</strong>. It expires in 10 minutes.</p>\n <p>If you didn't request this, you can ignore this message.</p>\n `,\n text: `Welcome to rpcbase! Your verification code is ${emailVerificationCode}. It expires in 10 minutes. If you didn't request this, you can ignore this message.`,\n })\n } catch (err) {\n console.error(\"failed to send sign-up email\", err)\n\n try {\n await User.deleteOne({ _id: user._id })\n } catch (rollbackErr) {\n console.error(\"failed to roll back user after sign-up email failure\", rollbackErr)\n }\n\n ctx.res.status(500)\n return { success: false, error: \"email_delivery_failed\" }\n }\n\n try {\n await createProvisionedTenant(Tenant, {\n tenantId,\n name: email,\n })\n } catch (err) {\n console.error(\"failed to initialize tenant for user\", err)\n try {\n await User.deleteOne({ _id: user._id })\n } catch (rollbackErr) {\n console.error(\"failed to roll back user after tenant initialization failure\", rollbackErr)\n }\n ctx.res.status(500)\n return { success: false, error: \"tenant_initialization_failed\" }\n }\n\n console.log(\"created new user\", user._id.toString())\n\n return { success: true, userId: user._id.toString(), tenantId }\n}\n\nexport default (api: Api<AuthSessionUser>) => {\n api.post(SignUp.ROUTE, signUp)\n}\n"],"mappings":";;;;;;AAYA,IAAaY,SAAqF,OAChGG,SACAC,QACoC;CACpC,MAAME,SAAAA,cAA8BE,UAAUL,OAAO;CAErD,IAAI,CAACG,OAAOG,SAAS;EACnBL,IAAIM,IAAIC,OAAO,GAAG;EAClB,OAAO;GAAEF,SAAS;GAAOG,OAAO;EAAkB;CACpD;CAGA,MAAM,EAAEC,OAAOC,UAAUC,YAAYC,gBAAgBV,OAAOW;CAE5D,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;EAClB,OAAO;GAAEF,SAAS;GAAOG,OAAO;EAAwB;CAC1D;CAEA,IAAI;EACF,MAAMpB,wBAAwB4B,QAAQ;GACpCM;GACAqB,MAAMlC;EACR,CAAC;CACH,SAAS8B,KAAK;EACZpB,QAAQX,MAAM,wCAAwC+B,GAAG;EACzD,IAAI;GACF,MAAMzB,KAAK0B,UAAU,EAAEC,KAAKV,KAAKU,IAAI,CAAC;EACxC,SAASC,aAAa;GACpBvB,QAAQX,MAAM,gEAAgEkC,WAAW;EAC3F;EACA1C,IAAIM,IAAIC,OAAO,GAAG;EAClB,OAAO;GAAEF,SAAS;GAAOG,OAAO;EAA+B;CACjE;CAEAW,QAAQC,IAAI,oBAAoBW,KAAKU,IAAIf,SAAS,CAAC;CAEnD,OAAO;EAAErB,SAAS;EAAMuC,QAAQb,KAAKU,IAAIf,SAAS;EAAGJ;CAAS;AAChE;AAEA,IAAA,mBAAgBuB,QAA8B;CAC5CA,IAAIC,KAAKnD,OAAcC,MAAM;AAC/B"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"handler-C7SfLP4c.js","names":["z","ROUTE","requestSchema","object","email","string","RequestPayload","infer","responseSchema","success","boolean","error","optional","ResponsePayload","crypto","Api","ApiHandler","Ctx","models","sendEmail","AuthSessionUser","ResendOtp","resendOtp","RequestPayload","ResponsePayload","payload","ctx","Promise","User","getGlobal","parsed","requestSchema","safeParse","success","res","status","error","email","data","user","findOne","emailVerificationCode","randomInt","toString","padStart","emailVerificationExpiresAt","Date","now","save","to","subject","html","text","err","console","updateOne","_id","$unset","releaseErr","api","post","ROUTE"],"sources":["../src/api/resend-otp/index.ts","../src/api/resend-otp/handler.ts"],"sourcesContent":["import { z } from \"zod\"\n\n\nexport const ROUTE = \"/api/rb/auth/resend-otp\"\n\nexport const requestSchema = z.object({\n email: z.string().email(),\n})\n\nexport type RequestPayload = z.infer<typeof requestSchema>\n\nexport const responseSchema = z.object({\n success: z.boolean(),\n error: z.string().optional(),\n})\n\nexport type ResponsePayload = z.infer<typeof responseSchema>\n\n","import crypto from \"crypto\"\n\nimport { Api, ApiHandler, Ctx } from \"@rpcbase/api\"\nimport { models } from \"@rpcbase/db\"\nimport { sendEmail } from \"@rpcbase/server\"\n\nimport type { AuthSessionUser } from \"../../types\"\n\nimport * as ResendOtp from \"./index\"\n\n\nexport const resendOtp: ApiHandler<ResendOtp.RequestPayload, ResendOtp.ResponsePayload, AuthSessionUser> = async (\n payload,\n ctx: Ctx<AuthSessionUser>\n): Promise<ResendOtp.ResponsePayload> => {\n const User = await models.getGlobal(\"RBUser\", ctx)\n\n const parsed = ResendOtp.requestSchema.safeParse(payload)\n\n if (!parsed.success) {\n ctx.res.status(400)\n return { success: false, error: \"invalid_payload\" }\n }\n\n const { email } = parsed.data\n\n const user = await User.findOne({ email })\n\n if (!user) {\n // TODO(auth): avoid account enumeration (return a generic success response even when the user doesn't exist)\n ctx.res.status(404)\n return { success: false, error: \"user_not_found\" }\n }\n\n // TODO(auth): add server-side throttling / rate limiting for resend-otp\n const emailVerificationCode = crypto.randomInt(0, 1_000_000).toString().padStart(6, \"0\")\n const emailVerificationExpiresAt = new Date(Date.now() + 10 * 60 * 1000)\n\n user.emailVerificationCode = emailVerificationCode\n user.emailVerificationExpiresAt = emailVerificationExpiresAt\n await user.save()\n\n try {\n await sendEmail({\n to: email,\n subject: `Your verification code: ${emailVerificationCode}`,\n html: `\n <p>Your verification code is <strong>${emailVerificationCode}</strong>. It expires in 10 minutes.</p>\n <p>If you didn't request this, you can ignore this message.</p>\n `,\n text: `Your verification code is ${emailVerificationCode}. It expires in 10 minutes. If you didn't request this, you can ignore this message.`,\n })\n } catch (err) {\n console.error(\"failed to resend otp email\", err)\n\n try {\n await User.updateOne(\n { _id: user._id, emailVerificationCode },\n {\n $unset: {\n emailVerificationCode: \"\",\n emailVerificationExpiresAt: \"\",\n },\n },\n )\n } catch (releaseErr) {\n console.error(\"failed to clear unsent otp\", releaseErr)\n }\n\n ctx.res.status(500)\n return { success: false, error: \"email_delivery_failed\" }\n }\n\n return { success: true }\n}\n\nexport default (api: Api<AuthSessionUser>) => {\n api.post(ResendOtp.ROUTE, resendOtp)\n}\n"],"mappings":";;;;;AAGA,IAAaC,QAAQ;AAErB,IAAaC,gBAAgBF,OAAS,EACpCI,OAAOJ,OAAS,CAAC,CAACI,MAAM,EAC1B,CAAC;AAI6BJ,OAAS;CACrCS,SAAST,QAAU;CACnBW,OAAOX,OAAS,CAAC,CAACY,SAAS;AAC7B,CAAC;;;ACHD,IAAaU,YAA8F,OACzGG,SACAC,QACuC;CACvC,MAAME,OAAO,MAAMV,OAAOW,UAAU,UAAUH,GAAG;CAEjD,MAAMI,SAAAA,cAAiCE,UAAUP,OAAO;CAExD,IAAI,CAACK,OAAOG,SAAS;EACnBP,IAAIQ,IAAIC,OAAO,GAAG;EAClB,OAAO;GAAEF,SAAS;GAAOG,OAAO;EAAkB;CACpD;CAEA,MAAM,EAAEC,UAAUP,OAAOQ;CAEzB,MAAMC,OAAO,MAAMX,KAAKY,QAAQ,EAAEH,MAAM,CAAC;CAEzC,IAAI,CAACE,MAAM;EAETb,IAAIQ,IAAIC,OAAO,GAAG;EAClB,OAAO;GAAEF,SAAS;GAAOG,OAAO;EAAiB;CACnD;CAGA,MAAMK,wBAAwB3B,OAAO4B,UAAU,GAAG,GAAS,CAAC,CAACC,SAAS,CAAC,CAACC,SAAS,GAAG,GAAG;CACvF,MAAMC,6BAA6B,IAAIC,KAAKA,KAAKC,IAAI,IAAI,MAAU,GAAI;CAEvER,KAAKE,wBAAwBA;CAC7BF,KAAKM,6BAA6BA;CAClC,MAAMN,KAAKS,KAAK;CAEhB,IAAI;EACF,MAAM7B,UAAU;GACd8B,IAAIZ;GACJa,SAAS,2BAA2BT;GACpCU,MAAM;+CACmCV,sBAAqB;;;GAG9DW,MAAM,6BAA6BX,sBAAqB;EAC1D,CAAC;CACH,SAASY,KAAK;EACZC,QAAQlB,MAAM,8BAA8BiB,GAAG;EAE/C,IAAI;GACF,MAAMzB,KAAK2B,UACT;IAAEC,KAAKjB,KAAKiB;IAAKf;GAAsB,GACvC,EACEgB,QAAQ;IACNhB,uBAAuB;IACvBI,4BAA4B;GAC9B,EACF,CACF;EACF,SAASa,YAAY;GACnBJ,QAAQlB,MAAM,8BAA8BsB,UAAU;EACxD;EAEAhC,IAAIQ,IAAIC,OAAO,GAAG;EAClB,OAAO;GAAEF,SAAS;GAAOG,OAAO;EAAwB;CAC1D;CAEA,OAAO,EAAEH,SAAS,KAAK;AACzB;AAEA,IAAA,mBAAgB0B,QAA8B;CAC5CA,IAAIC,KAAKvC,OAAiBC,SAAS;AACrC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"handler-aS6g_PVg.js","names":["z","ROUTE","requestSchema","object","email","string","RequestPayload","infer","responseSchema","success","boolean","error","optional","retryAfterSeconds","number","int","positive","ResponsePayload","crypto","Api","ApiHandler","Ctx","models","sendEmail","DISPOSABLE_EMAIL_ERROR_CODE","isDisposableEmailAddress","AuthSessionUser","RequestPasswordReset","PASSWORD_RESET_COOLDOWN_SECONDS","PASSWORD_RESET_CODE_TTL_SECONDS","maskEmailForLog","email","localRaw","domainRaw","split","local","domain","localPrefix","slice","Math","min","length","localMask","repeat","max","domainTailLength","domainTail","domainMask","requestPasswordReset","RequestPayload","ResponsePayload","payload","ctx","Promise","parsed","requestSchema","safeParse","success","res","status","error","data","User","getGlobal","requestedAt","Date","cooldownEligibleExpiresAt","getTime","passwordResetCode","randomInt","toString","padStart","passwordResetCodeExpiresAt","user","findOneAndUpdate","$or","$exists","$lte","$set","$unset","passwordResetToken","passwordResetTokenExpiresAt","returnDocument","setHeader","String","existingUser","findOne","_id","console","info","to","subject","html","text","err","retryAfterSeconds","releaseResult","updateOne","modifiedCount","removeHeader","releaseErr","api","post","ROUTE"],"sources":["../src/api/request-password-reset/index.ts","../src/api/request-password-reset/handler.ts"],"sourcesContent":["import { z } from \"zod\"\n\n\nexport const ROUTE = \"/api/rb/auth/request-password-reset\"\n\nexport const requestSchema = z.object({\n email: z.string().email(),\n})\n\nexport type RequestPayload = z.infer<typeof requestSchema>\n\nexport const responseSchema = z.object({\n success: z.boolean(),\n error: z.string().optional(),\n retryAfterSeconds: z.number().int().positive().optional(),\n})\n\nexport type ResponsePayload = z.infer<typeof responseSchema>\n","import crypto from \"crypto\"\n\nimport { Api, ApiHandler, Ctx } from \"@rpcbase/api\"\nimport { models } from \"@rpcbase/db\"\nimport { sendEmail } from \"@rpcbase/server\"\n\nimport { DISPOSABLE_EMAIL_ERROR_CODE, isDisposableEmailAddress } from \"../../email-validation\"\nimport type { AuthSessionUser } from \"../../types\"\n\nimport * as RequestPasswordReset from \"./index\"\n\n\nexport const PASSWORD_RESET_COOLDOWN_SECONDS = 60\nconst PASSWORD_RESET_CODE_TTL_SECONDS = 10 * 60\n\nconst maskEmailForLog = (email: string) => {\n const [localRaw, domainRaw = \"\"] = email.split(\"@\")\n const local = localRaw || \"\"\n const domain = domainRaw || \"\"\n const localPrefix = local.slice(0, Math.min(3, local.length))\n const localMask = \"*\".repeat(Math.max(5, local.length - localPrefix.length))\n\n if (!domain) {\n return `${localPrefix}${localMask}@****`\n }\n\n const domainTailLength = Math.min(7, domain.length)\n const domainTail = domain.slice(-domainTailLength)\n const domainMask = \"*\".repeat(Math.max(4, domain.length - domainTailLength))\n\n return `${localPrefix}${localMask}@${domainMask}${domainTail}`\n}\n\n\nexport const requestPasswordReset: ApiHandler<\n RequestPasswordReset.RequestPayload,\n RequestPasswordReset.ResponsePayload,\n AuthSessionUser\n> = async(\n payload,\n ctx: Ctx<AuthSessionUser>\n): Promise<RequestPasswordReset.ResponsePayload> => {\n const parsed = RequestPasswordReset.requestSchema.safeParse(payload)\n\n if (!parsed.success) {\n ctx.res.status(400)\n return { success: false, error: \"invalid_payload\" }\n }\n\n const { email } = parsed.data\n\n if (await isDisposableEmailAddress(email)) {\n ctx.res.status(400)\n return { success: false, error: DISPOSABLE_EMAIL_ERROR_CODE }\n }\n\n const User = await models.getGlobal(\"RBUser\", ctx)\n const requestedAt = new Date()\n const cooldownEligibleExpiresAt = new Date(\n requestedAt.getTime() + (PASSWORD_RESET_CODE_TTL_SECONDS - PASSWORD_RESET_COOLDOWN_SECONDS) * 1000,\n )\n const passwordResetCode = crypto.randomInt(0, 1_000_000).toString().padStart(6, \"0\")\n const passwordResetCodeExpiresAt = new Date(requestedAt.getTime() + PASSWORD_RESET_CODE_TTL_SECONDS * 1000)\n\n const user = await User.findOneAndUpdate(\n {\n email,\n $or: [\n { passwordResetCodeExpiresAt: { $exists: false } },\n { passwordResetCodeExpiresAt: { $lte: cooldownEligibleExpiresAt } },\n ],\n },\n {\n $set: {\n passwordResetCode,\n passwordResetCodeExpiresAt,\n },\n $unset: {\n passwordResetToken: \"\",\n passwordResetTokenExpiresAt: \"\",\n },\n },\n { returnDocument: \"after\" },\n )\n\n ctx.res.setHeader(\"Retry-After\", String(PASSWORD_RESET_COOLDOWN_SECONDS))\n\n if (!user) {\n const existingUser = await User.findOne({ email }, { _id: 1 })\n\n if (!existingUser) {\n try {\n console.info(`sending password reset account notice to email ${maskEmailForLog(email)}`)\n await sendEmail({\n to: email,\n subject: \"No account found for your password reset request\",\n html: `\n <p>Hello,</p>\n <p>You requested a new password reset code for this email address, but unfortunately we couldn't find an account associated with it.</p>\n <p>If you didn't request this, you can ignore this message.</p>\n <p>If you're having trouble accessing your account, please contact support.</p>\n `,\n text: \"Hello, You requested a new password reset code for this email address, but unfortunately we couldn't find an account associated with it. If you didn't request this, you can ignore this message. If you're having trouble accessing your account, please contact support.\",\n })\n } catch (err) {\n console.error(\"failed to send password reset account notice email\", err)\n ctx.res.status(500)\n return { success: false, error: \"email_delivery_failed\" }\n }\n }\n\n return { success: true, retryAfterSeconds: PASSWORD_RESET_COOLDOWN_SECONDS }\n }\n\n try {\n console.info(`sending password reset to email ${maskEmailForLog(email)}`)\n await sendEmail({\n to: email,\n subject: `Your password reset code: ${passwordResetCode}`,\n html: `\n <p>Your password reset code is <strong>${passwordResetCode}</strong>. It expires in 10 minutes.</p>\n <p>If you didn't request this, you can ignore this message.</p>\n `,\n text: `Your password reset code is ${passwordResetCode}. It expires in 10 minutes. If you didn't request this, you can ignore this message.`,\n })\n } catch (err) {\n console.error(\"failed to send password reset email\", err)\n\n try {\n const releaseResult = await User.updateOne(\n { _id: user._id, passwordResetCode },\n {\n $unset: {\n passwordResetCode: \"\",\n passwordResetCodeExpiresAt: \"\",\n },\n },\n )\n if (releaseResult.modifiedCount > 0) {\n ctx.res.removeHeader(\"Retry-After\")\n }\n } catch (releaseErr) {\n console.error(\"failed to release password reset cooldown\", releaseErr)\n }\n\n ctx.res.status(500)\n return { success: false, error: \"email_delivery_failed\" }\n }\n\n return { success: true, retryAfterSeconds: PASSWORD_RESET_COOLDOWN_SECONDS }\n}\n\nexport default (api: Api<AuthSessionUser>) => {\n api.post(RequestPasswordReset.ROUTE, requestPasswordReset)\n}\n"],"mappings":";;;;;;AAGA,IAAaC,QAAQ;AAErB,IAAaC,gBAAgBF,OAAS,EACpCI,OAAOJ,OAAS,CAAC,CAACI,MAAM,EAC1B,CAAC;AAI6BJ,OAAS;CACrCS,SAAST,QAAU;CACnBW,OAAOX,OAAS,CAAC,CAACY,SAAS;CAC3BC,mBAAmBb,OAAS,CAAC,CAACe,IAAI,CAAC,CAACC,SAAS,CAAC,CAACJ,SAAS;AAC1D,CAAC;;;ACHD,IAAagB,kCAAkC;AAC/C,IAAMC,kCAAkC;AAExC,IAAMC,mBAAmBC,UAAkB;CACzC,MAAM,CAACC,UAAUC,YAAY,MAAMF,MAAMG,MAAM,GAAG;CAClD,MAAMC,QAAQH,YAAY;CAC1B,MAAMI,SAASH,aAAa;CAC5B,MAAMI,cAAcF,MAAMG,MAAM,GAAGC,KAAKC,IAAI,GAAGL,MAAMM,MAAM,CAAC;CAC5D,MAAMC,YAAY,IAAIC,OAAOJ,KAAKK,IAAI,GAAGT,MAAMM,SAASJ,YAAYI,MAAM,CAAC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