@webtwizz/cloud 0.2.0 → 0.3.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/AI_GUIDE.md +2 -0
- package/CHANGELOG.md +6 -0
- package/dist/server.js +20 -2
- package/package.json +1 -1
package/AI_GUIDE.md
CHANGED
|
@@ -41,6 +41,8 @@ if (error) setMessage(authMessage(error));
|
|
|
41
41
|
|
|
42
42
|
For wording that fits the site, pass overrides: `authMessage(error, { USER_ALREADY_EXISTS: 'You already have a booking account.' })`.
|
|
43
43
|
|
|
44
|
+
When the owner turns on Confirm email, sign-up returns no session and the 6-digit code is emailed automatically. Show a code step: `authClient.emailOtp.verifyEmail({ email, otp })`, then sign them in, with a "Send a new code" button that calls `authClient.emailOtp.sendVerificationOtp({ email, type: 'email-verification' })`. Never send the first code yourself.
|
|
45
|
+
|
|
44
46
|
5. Protect pages in `src/proxy.ts`, listing only the protected routes in the matcher (a matcher over every path blocks the sign-in page's own scripts):
|
|
45
47
|
|
|
46
48
|
```ts
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @webtwizz/cloud
|
|
2
2
|
|
|
3
|
+
## 0.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- f6f3ed3: When Confirm email is on, the sign-up code now goes out through WebTwizz's own emails: the site's sign-in route asks for it right after a sign-up that needs confirming.
|
|
8
|
+
|
|
3
9
|
## 0.2.0
|
|
4
10
|
|
|
5
11
|
### Minor Changes
|
package/dist/server.js
CHANGED
|
@@ -1458,9 +1458,20 @@ function forBrowser(response) {
|
|
|
1458
1458
|
return new Response(response.body, { status: response.status, statusText: response.statusText, headers: headers2 });
|
|
1459
1459
|
}
|
|
1460
1460
|
}
|
|
1461
|
+
async function sendSignUpCode(baseUrl, request, response) {
|
|
1462
|
+
const data = await response.clone().json().catch(() => null);
|
|
1463
|
+
const email = data?.user?.email;
|
|
1464
|
+
if (!email || data.user.emailVerified !== false || data.token) return;
|
|
1465
|
+
await fetch(`${baseUrl.replace(/\/+$/, "")}/email-otp/send-verification-otp`, {
|
|
1466
|
+
method: "POST",
|
|
1467
|
+
headers: { "content-type": "application/json", origin: request.headers.get("origin") || new URL(request.url).origin },
|
|
1468
|
+
body: JSON.stringify({ email, type: "email-verification" })
|
|
1469
|
+
}).catch((error) => console.error("[webtwizz-auth] Could not send the sign-up code", error));
|
|
1470
|
+
}
|
|
1461
1471
|
function createAuth(options = {}) {
|
|
1472
|
+
const baseUrl = options.url ?? env("WEBTWIZZ_AUTH_URL");
|
|
1462
1473
|
const auth = createNeonAuth({
|
|
1463
|
-
baseUrl
|
|
1474
|
+
baseUrl,
|
|
1464
1475
|
cookies: {
|
|
1465
1476
|
secret: options.secret ?? env("WEBTWIZZ_AUTH_SECRET"),
|
|
1466
1477
|
sessionDataTtl: options.sessionDataTtl
|
|
@@ -1471,7 +1482,14 @@ function createAuth(options = {}) {
|
|
|
1471
1482
|
auth.handler = () => {
|
|
1472
1483
|
const methods = handler();
|
|
1473
1484
|
const wrap = (method) => async (request, context) => forBrowser(await method(forLibrary(request, (original, headers2) => new Request(original, { headers: headers2 })), context));
|
|
1474
|
-
|
|
1485
|
+
const post = wrap(methods.POST);
|
|
1486
|
+
const signUp = async (request, context) => {
|
|
1487
|
+
const response = await post(request, context);
|
|
1488
|
+
const { path } = await context.params;
|
|
1489
|
+
if (response.ok && path?.join("/") === "sign-up/email") await sendSignUpCode(baseUrl, request, response);
|
|
1490
|
+
return response;
|
|
1491
|
+
};
|
|
1492
|
+
return { GET: wrap(methods.GET), POST: signUp, PUT: wrap(methods.PUT), DELETE: wrap(methods.DELETE), PATCH: wrap(methods.PATCH) };
|
|
1475
1493
|
};
|
|
1476
1494
|
auth.middleware = (config) => {
|
|
1477
1495
|
const run = middleware(config);
|