@arch-cadre/auth 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/actions/basic.cjs +46 -0
- package/dist/actions/basic.d.ts +14 -0
- package/dist/actions/basic.mjs +32 -0
- package/dist/actions/email.cjs +209 -0
- package/dist/actions/email.d.ts +7 -0
- package/dist/actions/email.mjs +186 -0
- package/dist/actions/index.cjs +27 -0
- package/dist/actions/index.d.ts +2 -0
- package/dist/actions/index.mjs +2 -0
- package/dist/index.cjs +16 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.mjs +9 -0
- package/dist/intl.d.ts +13 -0
- package/dist/routes.cjs +46 -0
- package/dist/routes.d.ts +2 -0
- package/dist/routes.mjs +48 -0
- package/dist/types.cjs +1 -0
- package/dist/types.d.ts +12 -0
- package/dist/types.mjs +0 -0
- package/dist/ui/forgot-password/components.cjs +91 -0
- package/dist/ui/forgot-password/components.d.ts +2 -0
- package/dist/ui/forgot-password/components.mjs +63 -0
- package/dist/ui/forgot-password/page.cjs +13 -0
- package/dist/ui/forgot-password/page.d.ts +2 -0
- package/dist/ui/forgot-password/page.mjs +5 -0
- package/dist/ui/layout.cjs +39 -0
- package/dist/ui/layout.d.ts +4 -0
- package/dist/ui/layout.mjs +18 -0
- package/dist/ui/reset-password/components.cjs +109 -0
- package/dist/ui/reset-password/components.d.ts +2 -0
- package/dist/ui/reset-password/components.mjs +84 -0
- package/dist/ui/reset-password/page.cjs +29 -0
- package/dist/ui/reset-password/page.d.ts +2 -0
- package/dist/ui/reset-password/page.mjs +21 -0
- package/dist/ui/reset-password/verify-email/components.cjs +106 -0
- package/dist/ui/reset-password/verify-email/components.d.ts +4 -0
- package/dist/ui/reset-password/verify-email/components.mjs +62 -0
- package/dist/ui/reset-password/verify-email/page.cjs +31 -0
- package/dist/ui/reset-password/verify-email/page.d.ts +2 -0
- package/dist/ui/reset-password/verify-email/page.mjs +21 -0
- package/dist/ui/signin/components.cjs +172 -0
- package/dist/ui/signin/components.d.ts +11 -0
- package/dist/ui/signin/components.mjs +134 -0
- package/dist/ui/signin/page.cjs +41 -0
- package/dist/ui/signin/page.d.ts +2 -0
- package/dist/ui/signin/page.mjs +39 -0
- package/dist/ui/signup/components.cjs +193 -0
- package/dist/ui/signup/components.d.ts +11 -0
- package/dist/ui/signup/components.mjs +150 -0
- package/dist/ui/signup/page.cjs +36 -0
- package/dist/ui/signup/page.d.ts +2 -0
- package/dist/ui/signup/page.mjs +34 -0
- package/dist/ui/verify-email/components.cjs +129 -0
- package/dist/ui/verify-email/components.d.ts +4 -0
- package/dist/ui/verify-email/components.mjs +76 -0
- package/dist/ui/verify-email/page.cjs +29 -0
- package/dist/ui/verify-email/page.d.ts +2 -0
- package/dist/ui/verify-email/page.mjs +21 -0
- package/dist/validation.cjs +43 -0
- package/dist/validation.d.ts +97 -0
- package/dist/validation.mjs +37 -0
- package/locales/en/global.json +35 -0
- package/manifest.json +11 -0
- package/package.json +57 -0
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.SignUpForm = SignUpForm;
|
|
8
|
+
exports.useSignUpForm = useSignUpForm;
|
|
9
|
+
var _intl = require("@arch-cadre/intl");
|
|
10
|
+
var _button = require("@arch-cadre/ui/components/button");
|
|
11
|
+
var _checkbox = require("@arch-cadre/ui/components/checkbox");
|
|
12
|
+
var _field = require("@arch-cadre/ui/components/field");
|
|
13
|
+
var _input = require("@arch-cadre/ui/components/input");
|
|
14
|
+
var _separator = require("@arch-cadre/ui/components/separator");
|
|
15
|
+
var _utils = require("@arch-cadre/ui/lib/utils");
|
|
16
|
+
var _loader = require("@arch-cadre/ui/shared/loader");
|
|
17
|
+
var _zod = require("@hookform/resolvers/zod");
|
|
18
|
+
var _lucideReact = require("lucide-react");
|
|
19
|
+
var _link = _interopRequireDefault(require("next/link"));
|
|
20
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
21
|
+
var React = _react;
|
|
22
|
+
var _reactHookForm = require("react-hook-form");
|
|
23
|
+
var _sonner = require("sonner");
|
|
24
|
+
var _index = require("../../actions/index.cjs");
|
|
25
|
+
var _validation = require("../../validation.cjs");
|
|
26
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
27
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
28
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
29
|
+
const SignUpFormContext = (0, _react.createContext)(null);
|
|
30
|
+
function useSignUpForm() {
|
|
31
|
+
const context = (0, _react.useContext)(SignUpFormContext);
|
|
32
|
+
if (!context) {
|
|
33
|
+
throw new Error("useSignUpForm must be used within a SignUpForm");
|
|
34
|
+
}
|
|
35
|
+
return context;
|
|
36
|
+
}
|
|
37
|
+
function SignUpForm({
|
|
38
|
+
extraButtons,
|
|
39
|
+
extraFields,
|
|
40
|
+
hasAllowedExtraButtons
|
|
41
|
+
}) {
|
|
42
|
+
const [generalError, setGeneralError] = (0, _react.useState)("");
|
|
43
|
+
const {
|
|
44
|
+
t
|
|
45
|
+
} = (0, _intl.useTranslation)();
|
|
46
|
+
const form = (0, _reactHookForm.useForm)({
|
|
47
|
+
resolver: (0, _zod.zodResolver)(_validation.registerSchema)
|
|
48
|
+
});
|
|
49
|
+
async function onSubmit(data) {
|
|
50
|
+
setGeneralError("");
|
|
51
|
+
try {
|
|
52
|
+
const response = await (0, _index.signupAction)(data);
|
|
53
|
+
if (response.error) {
|
|
54
|
+
setGeneralError(response.message || t("error_occurred"));
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
(0, _sonner.toast)(response.message);
|
|
58
|
+
} catch (_error) {}
|
|
59
|
+
}
|
|
60
|
+
return /* @__PURE__ */React.createElement(SignUpFormContext.Provider, {
|
|
61
|
+
value: {
|
|
62
|
+
form
|
|
63
|
+
}
|
|
64
|
+
}, /* @__PURE__ */React.createElement("div", {
|
|
65
|
+
className: (0, _utils.cn)("flex flex-col space-y-6")
|
|
66
|
+
}, /* @__PURE__ */React.createElement("div", {
|
|
67
|
+
className: "space-y-2 text-center"
|
|
68
|
+
}, /* @__PURE__ */React.createElement("h1", {
|
|
69
|
+
className: "text-3xl font-semibold"
|
|
70
|
+
}, t("Sign Up")), /* @__PURE__ */React.createElement("p", {
|
|
71
|
+
className: "text-muted-foreground"
|
|
72
|
+
}, t("Sign up to access your dashboard, settings and projects."))), /* @__PURE__ */React.createElement("div", {
|
|
73
|
+
className: "grid gap-5"
|
|
74
|
+
}, hasAllowedExtraButtons && /* @__PURE__ */React.createElement(React.Fragment, null, /* @__PURE__ */React.createElement("div", {
|
|
75
|
+
className: "flex flex-col gap-2"
|
|
76
|
+
}, extraButtons), /* @__PURE__ */React.createElement("div", {
|
|
77
|
+
className: "flex items-center gap-2"
|
|
78
|
+
}, /* @__PURE__ */React.createElement(_separator.Separator, {
|
|
79
|
+
className: "flex-1"
|
|
80
|
+
}), /* @__PURE__ */React.createElement("span", {
|
|
81
|
+
className: "text-sm text-muted-foreground"
|
|
82
|
+
}, t("or sign up with email")), /* @__PURE__ */React.createElement(_separator.Separator, {
|
|
83
|
+
className: "flex-1"
|
|
84
|
+
}))), generalError && /* @__PURE__ */React.createElement("div", {
|
|
85
|
+
className: "flex gap-2 p-3 bg-red-50 border border-red-200 rounded-lg"
|
|
86
|
+
}, /* @__PURE__ */React.createElement(_lucideReact.AlertCircle, {
|
|
87
|
+
className: "w-4 h-4 text-red-600 flex-shrink-0 mt-0.5"
|
|
88
|
+
}), /* @__PURE__ */React.createElement("p", {
|
|
89
|
+
className: "text-sm text-red-600"
|
|
90
|
+
}, generalError)), /* @__PURE__ */React.createElement("form", {
|
|
91
|
+
onSubmit: form.handleSubmit(onSubmit),
|
|
92
|
+
className: "grid gap-6"
|
|
93
|
+
}, /* @__PURE__ */React.createElement(_field.FieldGroup, null, /* @__PURE__ */React.createElement(_reactHookForm.Controller, {
|
|
94
|
+
name: "email",
|
|
95
|
+
control: form.control,
|
|
96
|
+
render: ({
|
|
97
|
+
field,
|
|
98
|
+
fieldState
|
|
99
|
+
}) => /* @__PURE__ */React.createElement(_field.Field, {
|
|
100
|
+
"data-invalid": fieldState.invalid
|
|
101
|
+
}, /* @__PURE__ */React.createElement(_field.FieldLabel, {
|
|
102
|
+
htmlFor: "email"
|
|
103
|
+
}, t("Email address")), /* @__PURE__ */React.createElement(_input.Input, {
|
|
104
|
+
...field,
|
|
105
|
+
id: "email",
|
|
106
|
+
type: "email",
|
|
107
|
+
"aria-invalid": fieldState.invalid,
|
|
108
|
+
placeholder: t("Email address"),
|
|
109
|
+
autoComplete: "off"
|
|
110
|
+
}), fieldState.invalid && /* @__PURE__ */React.createElement(_field.FieldError, {
|
|
111
|
+
errors: [fieldState.error]
|
|
112
|
+
}))
|
|
113
|
+
}), /* @__PURE__ */React.createElement(_reactHookForm.Controller, {
|
|
114
|
+
name: "username",
|
|
115
|
+
control: form.control,
|
|
116
|
+
render: ({
|
|
117
|
+
field,
|
|
118
|
+
fieldState
|
|
119
|
+
}) => /* @__PURE__ */React.createElement(_field.Field, {
|
|
120
|
+
"data-invalid": fieldState.invalid
|
|
121
|
+
}, /* @__PURE__ */React.createElement(_field.FieldLabel, {
|
|
122
|
+
htmlFor: "username"
|
|
123
|
+
}, t("Username")), /* @__PURE__ */React.createElement(_input.Input, {
|
|
124
|
+
...field,
|
|
125
|
+
id: "username",
|
|
126
|
+
type: "text",
|
|
127
|
+
"aria-invalid": fieldState.invalid,
|
|
128
|
+
placeholder: t("Username"),
|
|
129
|
+
autoComplete: "off"
|
|
130
|
+
}), fieldState.invalid && /* @__PURE__ */React.createElement(_field.FieldError, {
|
|
131
|
+
errors: [fieldState.error]
|
|
132
|
+
}))
|
|
133
|
+
}), /* @__PURE__ */React.createElement(_reactHookForm.Controller, {
|
|
134
|
+
name: "password",
|
|
135
|
+
control: form.control,
|
|
136
|
+
render: ({
|
|
137
|
+
field,
|
|
138
|
+
fieldState
|
|
139
|
+
}) => /* @__PURE__ */React.createElement(_field.Field, {
|
|
140
|
+
"data-invalid": fieldState.invalid
|
|
141
|
+
}, /* @__PURE__ */React.createElement(_field.FieldLabel, {
|
|
142
|
+
htmlFor: "password"
|
|
143
|
+
}, t("Password")), /* @__PURE__ */React.createElement(_input.Input, {
|
|
144
|
+
...field,
|
|
145
|
+
id: "password",
|
|
146
|
+
type: "password",
|
|
147
|
+
"aria-invalid": fieldState.invalid,
|
|
148
|
+
placeholder: t("Password"),
|
|
149
|
+
autoComplete: "off"
|
|
150
|
+
}), fieldState.invalid && /* @__PURE__ */React.createElement(_field.FieldError, {
|
|
151
|
+
errors: [fieldState.error]
|
|
152
|
+
}))
|
|
153
|
+
}), extraFields, /* @__PURE__ */React.createElement(_reactHookForm.Controller, {
|
|
154
|
+
name: "terms",
|
|
155
|
+
control: form.control,
|
|
156
|
+
render: ({
|
|
157
|
+
field,
|
|
158
|
+
fieldState
|
|
159
|
+
}) => /* @__PURE__ */React.createElement(_field.Field, {
|
|
160
|
+
"data-invalid": fieldState.invalid,
|
|
161
|
+
className: "flex items-center space-x-2"
|
|
162
|
+
}, /* @__PURE__ */React.createElement("div", {
|
|
163
|
+
className: "flex items-center space-x-2"
|
|
164
|
+
}, /* @__PURE__ */React.createElement(_checkbox.Checkbox, {
|
|
165
|
+
id: "terms",
|
|
166
|
+
"aria-invalid": fieldState.invalid,
|
|
167
|
+
checked: field.value,
|
|
168
|
+
onCheckedChange: checked => field.onChange(checked)
|
|
169
|
+
}), /* @__PURE__ */React.createElement(_field.FieldLabel, {
|
|
170
|
+
htmlFor: "terms",
|
|
171
|
+
className: "text-sm text-muted-foreground"
|
|
172
|
+
}, t("I agree to the"), " ", /* @__PURE__ */React.createElement(_link.default, {
|
|
173
|
+
href: "#",
|
|
174
|
+
className: "text-primary hover:underline"
|
|
175
|
+
}, t("Terms")), " ", t("and"), " ", /* @__PURE__ */React.createElement(_link.default, {
|
|
176
|
+
href: "#",
|
|
177
|
+
className: "text-primary hover:underline"
|
|
178
|
+
}, t("Privacy Policy")))), fieldState.invalid && /* @__PURE__ */React.createElement(_field.FieldError, {
|
|
179
|
+
errors: [fieldState.error]
|
|
180
|
+
}))
|
|
181
|
+
})), /* @__PURE__ */React.createElement(_button.Button, {
|
|
182
|
+
disabled: form.formState.isSubmitting,
|
|
183
|
+
className: "w-full"
|
|
184
|
+
}, form.formState.isSubmitting ? t("Please wait...") : t("Sign Up"), form.formState.isSubmitting && /* @__PURE__ */React.createElement(_loader.Loader, {
|
|
185
|
+
variant: "dark"
|
|
186
|
+
}))), /* @__PURE__ */React.createElement("div", {
|
|
187
|
+
className: "text-center text-sm"
|
|
188
|
+
}, t("Already have an account?"), " ", /* @__PURE__ */React.createElement(_link.default, {
|
|
189
|
+
key: "signin",
|
|
190
|
+
href: "/signin",
|
|
191
|
+
className: "underline underline-offset-4"
|
|
192
|
+
}, t("Sign In"))))));
|
|
193
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { UseFormReturn } from "react-hook-form";
|
|
3
|
+
import { type RegisterInput } from "../../validation";
|
|
4
|
+
export declare function useSignUpForm(): {
|
|
5
|
+
form: UseFormReturn<RegisterInput>;
|
|
6
|
+
};
|
|
7
|
+
export declare function SignUpForm({ extraButtons, extraFields, hasAllowedExtraButtons, }: {
|
|
8
|
+
extraButtons?: React.ReactNode;
|
|
9
|
+
extraFields?: React.ReactNode;
|
|
10
|
+
hasAllowedExtraButtons?: boolean;
|
|
11
|
+
}): React.JSX.Element;
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useTranslation } from "@arch-cadre/intl";
|
|
3
|
+
import { Button } from "@arch-cadre/ui/components/button";
|
|
4
|
+
import { Checkbox } from "@arch-cadre/ui/components/checkbox";
|
|
5
|
+
import {
|
|
6
|
+
Field,
|
|
7
|
+
FieldError,
|
|
8
|
+
FieldGroup,
|
|
9
|
+
FieldLabel
|
|
10
|
+
} from "@arch-cadre/ui/components/field";
|
|
11
|
+
import { Input } from "@arch-cadre/ui/components/input";
|
|
12
|
+
import { Separator } from "@arch-cadre/ui/components/separator";
|
|
13
|
+
import { cn } from "@arch-cadre/ui/lib/utils";
|
|
14
|
+
import { Loader } from "@arch-cadre/ui/shared/loader";
|
|
15
|
+
import { zodResolver } from "@hookform/resolvers/zod";
|
|
16
|
+
import { AlertCircle } from "lucide-react";
|
|
17
|
+
import Link from "next/link";
|
|
18
|
+
import * as React from "react";
|
|
19
|
+
import { createContext, useContext, useState } from "react";
|
|
20
|
+
import { Controller, useForm } from "react-hook-form";
|
|
21
|
+
import { toast } from "sonner";
|
|
22
|
+
import { signupAction } from "../../actions/index.mjs";
|
|
23
|
+
import { registerSchema } from "../../validation.mjs";
|
|
24
|
+
const SignUpFormContext = createContext(null);
|
|
25
|
+
export function useSignUpForm() {
|
|
26
|
+
const context = useContext(SignUpFormContext);
|
|
27
|
+
if (!context) {
|
|
28
|
+
throw new Error("useSignUpForm must be used within a SignUpForm");
|
|
29
|
+
}
|
|
30
|
+
return context;
|
|
31
|
+
}
|
|
32
|
+
export function SignUpForm({
|
|
33
|
+
extraButtons,
|
|
34
|
+
extraFields,
|
|
35
|
+
hasAllowedExtraButtons
|
|
36
|
+
}) {
|
|
37
|
+
const [generalError, setGeneralError] = useState("");
|
|
38
|
+
const { t } = useTranslation();
|
|
39
|
+
const form = useForm({
|
|
40
|
+
resolver: zodResolver(registerSchema)
|
|
41
|
+
});
|
|
42
|
+
async function onSubmit(data) {
|
|
43
|
+
setGeneralError("");
|
|
44
|
+
try {
|
|
45
|
+
const response = await signupAction(data);
|
|
46
|
+
if (response.error) {
|
|
47
|
+
setGeneralError(response.message || t("error_occurred"));
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
toast(response.message);
|
|
51
|
+
} catch (_error) {
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return /* @__PURE__ */ React.createElement(SignUpFormContext.Provider, { value: { form } }, /* @__PURE__ */ React.createElement("div", { className: cn("flex flex-col space-y-6") }, /* @__PURE__ */ React.createElement("div", { className: "space-y-2 text-center" }, /* @__PURE__ */ React.createElement("h1", { className: "text-3xl font-semibold" }, t("Sign Up")), /* @__PURE__ */ React.createElement("p", { className: "text-muted-foreground" }, t("Sign up to access your dashboard, settings and projects."))), /* @__PURE__ */ React.createElement("div", { className: "grid gap-5" }, hasAllowedExtraButtons && /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", { className: "flex flex-col gap-2" }, extraButtons), /* @__PURE__ */ React.createElement("div", { className: "flex items-center gap-2" }, /* @__PURE__ */ React.createElement(Separator, { className: "flex-1" }), /* @__PURE__ */ React.createElement("span", { className: "text-sm text-muted-foreground" }, t("or sign up with email")), /* @__PURE__ */ React.createElement(Separator, { className: "flex-1" }))), generalError && /* @__PURE__ */ React.createElement("div", { className: "flex gap-2 p-3 bg-red-50 border border-red-200 rounded-lg" }, /* @__PURE__ */ React.createElement(AlertCircle, { className: "w-4 h-4 text-red-600 flex-shrink-0 mt-0.5" }), /* @__PURE__ */ React.createElement("p", { className: "text-sm text-red-600" }, generalError)), /* @__PURE__ */ React.createElement("form", { onSubmit: form.handleSubmit(onSubmit), className: "grid gap-6" }, /* @__PURE__ */ React.createElement(FieldGroup, null, /* @__PURE__ */ React.createElement(
|
|
55
|
+
Controller,
|
|
56
|
+
{
|
|
57
|
+
name: "email",
|
|
58
|
+
control: form.control,
|
|
59
|
+
render: ({ field, fieldState }) => /* @__PURE__ */ React.createElement(Field, { "data-invalid": fieldState.invalid }, /* @__PURE__ */ React.createElement(FieldLabel, { htmlFor: "email" }, t("Email address")), /* @__PURE__ */ React.createElement(
|
|
60
|
+
Input,
|
|
61
|
+
{
|
|
62
|
+
...field,
|
|
63
|
+
id: "email",
|
|
64
|
+
type: "email",
|
|
65
|
+
"aria-invalid": fieldState.invalid,
|
|
66
|
+
placeholder: t("Email address"),
|
|
67
|
+
autoComplete: "off"
|
|
68
|
+
}
|
|
69
|
+
), fieldState.invalid && /* @__PURE__ */ React.createElement(FieldError, { errors: [fieldState.error] }))
|
|
70
|
+
}
|
|
71
|
+
), /* @__PURE__ */ React.createElement(
|
|
72
|
+
Controller,
|
|
73
|
+
{
|
|
74
|
+
name: "username",
|
|
75
|
+
control: form.control,
|
|
76
|
+
render: ({ field, fieldState }) => /* @__PURE__ */ React.createElement(Field, { "data-invalid": fieldState.invalid }, /* @__PURE__ */ React.createElement(FieldLabel, { htmlFor: "username" }, t("Username")), /* @__PURE__ */ React.createElement(
|
|
77
|
+
Input,
|
|
78
|
+
{
|
|
79
|
+
...field,
|
|
80
|
+
id: "username",
|
|
81
|
+
type: "text",
|
|
82
|
+
"aria-invalid": fieldState.invalid,
|
|
83
|
+
placeholder: t("Username"),
|
|
84
|
+
autoComplete: "off"
|
|
85
|
+
}
|
|
86
|
+
), fieldState.invalid && /* @__PURE__ */ React.createElement(FieldError, { errors: [fieldState.error] }))
|
|
87
|
+
}
|
|
88
|
+
), /* @__PURE__ */ React.createElement(
|
|
89
|
+
Controller,
|
|
90
|
+
{
|
|
91
|
+
name: "password",
|
|
92
|
+
control: form.control,
|
|
93
|
+
render: ({ field, fieldState }) => /* @__PURE__ */ React.createElement(Field, { "data-invalid": fieldState.invalid }, /* @__PURE__ */ React.createElement(FieldLabel, { htmlFor: "password" }, t("Password")), /* @__PURE__ */ React.createElement(
|
|
94
|
+
Input,
|
|
95
|
+
{
|
|
96
|
+
...field,
|
|
97
|
+
id: "password",
|
|
98
|
+
type: "password",
|
|
99
|
+
"aria-invalid": fieldState.invalid,
|
|
100
|
+
placeholder: t("Password"),
|
|
101
|
+
autoComplete: "off"
|
|
102
|
+
}
|
|
103
|
+
), fieldState.invalid && /* @__PURE__ */ React.createElement(FieldError, { errors: [fieldState.error] }))
|
|
104
|
+
}
|
|
105
|
+
), extraFields, /* @__PURE__ */ React.createElement(
|
|
106
|
+
Controller,
|
|
107
|
+
{
|
|
108
|
+
name: "terms",
|
|
109
|
+
control: form.control,
|
|
110
|
+
render: ({ field, fieldState }) => /* @__PURE__ */ React.createElement(
|
|
111
|
+
Field,
|
|
112
|
+
{
|
|
113
|
+
"data-invalid": fieldState.invalid,
|
|
114
|
+
className: "flex items-center space-x-2"
|
|
115
|
+
},
|
|
116
|
+
/* @__PURE__ */ React.createElement("div", { className: "flex items-center space-x-2" }, /* @__PURE__ */ React.createElement(
|
|
117
|
+
Checkbox,
|
|
118
|
+
{
|
|
119
|
+
id: "terms",
|
|
120
|
+
"aria-invalid": fieldState.invalid,
|
|
121
|
+
checked: field.value,
|
|
122
|
+
onCheckedChange: (checked) => field.onChange(checked)
|
|
123
|
+
}
|
|
124
|
+
), /* @__PURE__ */ React.createElement(
|
|
125
|
+
FieldLabel,
|
|
126
|
+
{
|
|
127
|
+
htmlFor: "terms",
|
|
128
|
+
className: "text-sm text-muted-foreground"
|
|
129
|
+
},
|
|
130
|
+
t("I agree to the"),
|
|
131
|
+
" ",
|
|
132
|
+
/* @__PURE__ */ React.createElement(Link, { href: "#", className: "text-primary hover:underline" }, t("Terms")),
|
|
133
|
+
" ",
|
|
134
|
+
t("and"),
|
|
135
|
+
" ",
|
|
136
|
+
/* @__PURE__ */ React.createElement(Link, { href: "#", className: "text-primary hover:underline" }, t("Privacy Policy"))
|
|
137
|
+
)),
|
|
138
|
+
fieldState.invalid && /* @__PURE__ */ React.createElement(FieldError, { errors: [fieldState.error] })
|
|
139
|
+
)
|
|
140
|
+
}
|
|
141
|
+
)), /* @__PURE__ */ React.createElement(Button, { disabled: form.formState.isSubmitting, className: "w-full" }, form.formState.isSubmitting ? t("Please wait...") : t("Sign Up"), form.formState.isSubmitting && /* @__PURE__ */ React.createElement(Loader, { variant: "dark" }))), /* @__PURE__ */ React.createElement("div", { className: "text-center text-sm" }, t("Already have an account?"), " ", /* @__PURE__ */ React.createElement(
|
|
142
|
+
Link,
|
|
143
|
+
{
|
|
144
|
+
key: "signin",
|
|
145
|
+
href: "/signin",
|
|
146
|
+
className: "underline underline-offset-4"
|
|
147
|
+
},
|
|
148
|
+
t("Sign In")
|
|
149
|
+
)))));
|
|
150
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
module.exports = Page;
|
|
7
|
+
var _server = require("@arch-cadre/core/server");
|
|
8
|
+
var _modules = require("@arch-cadre/modules");
|
|
9
|
+
var _navigation = require("next/navigation");
|
|
10
|
+
var React = _interopRequireWildcard(require("react"));
|
|
11
|
+
var _components = require("./components.cjs");
|
|
12
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
13
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
14
|
+
async function Page() {
|
|
15
|
+
const {
|
|
16
|
+
session,
|
|
17
|
+
user
|
|
18
|
+
} = await (0, _server.getCurrentSession)();
|
|
19
|
+
if (session !== null && user !== null) {
|
|
20
|
+
return (0, _navigation.redirect)("/");
|
|
21
|
+
}
|
|
22
|
+
const hasAllowed = await (0, _modules.hasExtension)("auth", "signup:extra-buttons");
|
|
23
|
+
return /* @__PURE__ */React.createElement(_components.SignUpForm, {
|
|
24
|
+
hasAllowedExtraButtons: hasAllowed,
|
|
25
|
+
extraButtons: /* @__PURE__ */React.createElement(_modules.ExtensionPoint, {
|
|
26
|
+
module: "auth",
|
|
27
|
+
point: "signup:extra-buttons",
|
|
28
|
+
className: "flex flex-col gap-2 mt-4"
|
|
29
|
+
}),
|
|
30
|
+
extraFields: /* @__PURE__ */React.createElement(_modules.ExtensionPoint, {
|
|
31
|
+
module: "auth",
|
|
32
|
+
point: "signup:extra-fields",
|
|
33
|
+
className: "flex flex-col gap-4"
|
|
34
|
+
})
|
|
35
|
+
});
|
|
36
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { getCurrentSession } from "@arch-cadre/core/server";
|
|
2
|
+
import { ExtensionPoint, hasExtension } from "@arch-cadre/modules";
|
|
3
|
+
import { redirect } from "next/navigation";
|
|
4
|
+
import * as React from "react";
|
|
5
|
+
import { SignUpForm } from "./components.mjs";
|
|
6
|
+
export default async function Page() {
|
|
7
|
+
const { session, user } = await getCurrentSession();
|
|
8
|
+
if (session !== null && user !== null) {
|
|
9
|
+
return redirect("/");
|
|
10
|
+
}
|
|
11
|
+
const hasAllowed = await hasExtension("auth", "signup:extra-buttons");
|
|
12
|
+
return /* @__PURE__ */ React.createElement(
|
|
13
|
+
SignUpForm,
|
|
14
|
+
{
|
|
15
|
+
hasAllowedExtraButtons: hasAllowed,
|
|
16
|
+
extraButtons: /* @__PURE__ */ React.createElement(
|
|
17
|
+
ExtensionPoint,
|
|
18
|
+
{
|
|
19
|
+
module: "auth",
|
|
20
|
+
point: "signup:extra-buttons",
|
|
21
|
+
className: "flex flex-col gap-2 mt-4"
|
|
22
|
+
}
|
|
23
|
+
),
|
|
24
|
+
extraFields: /* @__PURE__ */ React.createElement(
|
|
25
|
+
ExtensionPoint,
|
|
26
|
+
{
|
|
27
|
+
module: "auth",
|
|
28
|
+
point: "signup:extra-fields",
|
|
29
|
+
className: "flex flex-col gap-4"
|
|
30
|
+
}
|
|
31
|
+
)
|
|
32
|
+
}
|
|
33
|
+
);
|
|
34
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.EmailVerificationForm = EmailVerificationForm;
|
|
8
|
+
exports.ResendEmailVerificationCodeForm = ResendEmailVerificationCodeForm;
|
|
9
|
+
var _intl = require("@arch-cadre/intl");
|
|
10
|
+
var _button = require("@arch-cadre/ui/components/button");
|
|
11
|
+
var _field = require("@arch-cadre/ui/components/field");
|
|
12
|
+
var _inputOtp = require("@arch-cadre/ui/components/input-otp");
|
|
13
|
+
var _utils = require("@arch-cadre/ui/lib/utils");
|
|
14
|
+
var _loader = require("@arch-cadre/ui/shared/loader");
|
|
15
|
+
var _zod = require("@hookform/resolvers/zod");
|
|
16
|
+
var _lucideReact = require("lucide-react");
|
|
17
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
18
|
+
var _reactHookForm = require("react-hook-form");
|
|
19
|
+
var _sonner = require("sonner");
|
|
20
|
+
var _index = require("../../actions/index.cjs");
|
|
21
|
+
var _validation = require("../../validation.cjs");
|
|
22
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
23
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
24
|
+
function EmailVerificationForm({
|
|
25
|
+
email = ""
|
|
26
|
+
}) {
|
|
27
|
+
const [generalError, setGeneralError] = (0, _react.useState)("");
|
|
28
|
+
const {
|
|
29
|
+
t
|
|
30
|
+
} = (0, _intl.useTranslation)();
|
|
31
|
+
const form = (0, _reactHookForm.useForm)({
|
|
32
|
+
resolver: (0, _zod.zodResolver)(_validation.verifyEmailSchema)
|
|
33
|
+
});
|
|
34
|
+
async function onSubmit(data) {
|
|
35
|
+
setGeneralError("");
|
|
36
|
+
try {
|
|
37
|
+
const response = await (0, _index.verifyEmailAction)(data);
|
|
38
|
+
if (response.error) {
|
|
39
|
+
setGeneralError(response.message || t("error_occurred"));
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
(0, _sonner.toast)(response.message);
|
|
43
|
+
} catch (_error) {}
|
|
44
|
+
}
|
|
45
|
+
return /* @__PURE__ */_react.default.createElement("div", {
|
|
46
|
+
className: (0, _utils.cn)("flex flex-col space-y-6")
|
|
47
|
+
}, /* @__PURE__ */_react.default.createElement("div", {
|
|
48
|
+
className: "space-y-2 text-center"
|
|
49
|
+
}, /* @__PURE__ */_react.default.createElement("h1", {
|
|
50
|
+
className: "text-3xl font-semibold"
|
|
51
|
+
}, t("Verify email")), /* @__PURE__ */_react.default.createElement("p", {
|
|
52
|
+
className: "text-muted-foreground"
|
|
53
|
+
}, t("We've sent a verification code to your email address: {email}", {
|
|
54
|
+
email
|
|
55
|
+
}))), /* @__PURE__ */_react.default.createElement("div", {
|
|
56
|
+
className: "grid gap-6"
|
|
57
|
+
}, generalError && /* @__PURE__ */_react.default.createElement("div", {
|
|
58
|
+
className: "flex gap-2 p-3 bg-red-50 border border-red-200 rounded-lg"
|
|
59
|
+
}, /* @__PURE__ */_react.default.createElement(_lucideReact.AlertCircle, {
|
|
60
|
+
className: "w-4 h-4 text-red-600 flex-shrink-0 mt-0.5"
|
|
61
|
+
}), /* @__PURE__ */_react.default.createElement("p", {
|
|
62
|
+
className: "text-sm text-red-600"
|
|
63
|
+
}, generalError)), /* @__PURE__ */_react.default.createElement("form", {
|
|
64
|
+
onSubmit: form.handleSubmit(onSubmit),
|
|
65
|
+
className: "grid gap-5"
|
|
66
|
+
}, /* @__PURE__ */_react.default.createElement(_field.FieldGroup, {
|
|
67
|
+
className: "w-full mx-auto"
|
|
68
|
+
}, /* @__PURE__ */_react.default.createElement(_reactHookForm.Controller, {
|
|
69
|
+
name: "code",
|
|
70
|
+
control: form.control,
|
|
71
|
+
render: ({
|
|
72
|
+
field,
|
|
73
|
+
fieldState
|
|
74
|
+
}) => /* @__PURE__ */_react.default.createElement(_field.Field, {
|
|
75
|
+
className: "w-full",
|
|
76
|
+
"data-invalid": fieldState.invalid
|
|
77
|
+
}, /* @__PURE__ */_react.default.createElement(_inputOtp.InputOTP, {
|
|
78
|
+
...field,
|
|
79
|
+
className: "mx-auto w-full",
|
|
80
|
+
maxLength: 6,
|
|
81
|
+
autoFocus: true,
|
|
82
|
+
inputMode: "text"
|
|
83
|
+
}, /* @__PURE__ */_react.default.createElement(_inputOtp.InputOTPGroup, {
|
|
84
|
+
className: "mx-auto"
|
|
85
|
+
}, /* @__PURE__ */_react.default.createElement(_inputOtp.InputOTPSlot, {
|
|
86
|
+
index: 0
|
|
87
|
+
}), /* @__PURE__ */_react.default.createElement(_inputOtp.InputOTPSlot, {
|
|
88
|
+
index: 1
|
|
89
|
+
}), /* @__PURE__ */_react.default.createElement(_inputOtp.InputOTPSlot, {
|
|
90
|
+
index: 2
|
|
91
|
+
}), /* @__PURE__ */_react.default.createElement(_inputOtp.InputOTPSlot, {
|
|
92
|
+
index: 3
|
|
93
|
+
}), /* @__PURE__ */_react.default.createElement(_inputOtp.InputOTPSlot, {
|
|
94
|
+
index: 4
|
|
95
|
+
}), /* @__PURE__ */_react.default.createElement(_inputOtp.InputOTPSlot, {
|
|
96
|
+
index: 5
|
|
97
|
+
}))), fieldState.invalid && /* @__PURE__ */_react.default.createElement(_field.FieldError, {
|
|
98
|
+
errors: [fieldState.error]
|
|
99
|
+
}))
|
|
100
|
+
})), /* @__PURE__ */_react.default.createElement(_button.Button, {
|
|
101
|
+
disabled: form.formState.isSubmitting,
|
|
102
|
+
className: "w-full"
|
|
103
|
+
}, form.formState.isSubmitting ? t("Please wait...") : t("Verify Email"), form.formState.isSubmitting && /* @__PURE__ */_react.default.createElement(_loader.Loader, {
|
|
104
|
+
variant: "dark"
|
|
105
|
+
})))));
|
|
106
|
+
}
|
|
107
|
+
const resendEmailInitialState = {
|
|
108
|
+
message: ""
|
|
109
|
+
};
|
|
110
|
+
function ResendEmailVerificationCodeForm() {
|
|
111
|
+
const {
|
|
112
|
+
t
|
|
113
|
+
} = (0, _intl.useTranslation)();
|
|
114
|
+
const [state, action, isPending] = (0, _react.useActionState)(_index.resendEmailVerificationCodeAction, resendEmailInitialState);
|
|
115
|
+
(0, _react.useEffect)(() => {
|
|
116
|
+
if (state.message) {
|
|
117
|
+
_sonner.toast.success(state.message);
|
|
118
|
+
}
|
|
119
|
+
}, [state]);
|
|
120
|
+
return /* @__PURE__ */_react.default.createElement("form", {
|
|
121
|
+
action
|
|
122
|
+
}, /* @__PURE__ */_react.default.createElement(_button.Button, {
|
|
123
|
+
disabled: isPending,
|
|
124
|
+
variant: "ghost",
|
|
125
|
+
className: "w-full"
|
|
126
|
+
}, isPending ? t("Please wait...") : t("Resend verification email"), isPending && /* @__PURE__ */_react.default.createElement(_loader.Loader, {
|
|
127
|
+
variant: "default"
|
|
128
|
+
})));
|
|
129
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useTranslation } from "@arch-cadre/intl";
|
|
3
|
+
import { Button } from "@arch-cadre/ui/components/button";
|
|
4
|
+
import { Field, FieldError, FieldGroup } from "@arch-cadre/ui/components/field";
|
|
5
|
+
import {
|
|
6
|
+
InputOTP,
|
|
7
|
+
InputOTPGroup,
|
|
8
|
+
InputOTPSlot
|
|
9
|
+
} from "@arch-cadre/ui/components/input-otp";
|
|
10
|
+
import { cn } from "@arch-cadre/ui/lib/utils";
|
|
11
|
+
import { Loader } from "@arch-cadre/ui/shared/loader";
|
|
12
|
+
import { zodResolver } from "@hookform/resolvers/zod";
|
|
13
|
+
import { AlertCircle } from "lucide-react";
|
|
14
|
+
import React, { useActionState, useEffect, useState } from "react";
|
|
15
|
+
import { Controller, useForm } from "react-hook-form";
|
|
16
|
+
import { toast } from "sonner";
|
|
17
|
+
import {
|
|
18
|
+
resendEmailVerificationCodeAction,
|
|
19
|
+
verifyEmailAction
|
|
20
|
+
} from "../../actions/index.mjs";
|
|
21
|
+
import { verifyEmailSchema } from "../../validation.mjs";
|
|
22
|
+
export function EmailVerificationForm({ email = "" }) {
|
|
23
|
+
const [generalError, setGeneralError] = useState("");
|
|
24
|
+
const { t } = useTranslation();
|
|
25
|
+
const form = useForm({
|
|
26
|
+
resolver: zodResolver(verifyEmailSchema)
|
|
27
|
+
});
|
|
28
|
+
async function onSubmit(data) {
|
|
29
|
+
setGeneralError("");
|
|
30
|
+
try {
|
|
31
|
+
const response = await verifyEmailAction(data);
|
|
32
|
+
if (response.error) {
|
|
33
|
+
setGeneralError(response.message || t("error_occurred"));
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
toast(response.message);
|
|
37
|
+
} catch (_error) {
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return /* @__PURE__ */ React.createElement("div", { className: cn("flex flex-col space-y-6") }, /* @__PURE__ */ React.createElement("div", { className: "space-y-2 text-center" }, /* @__PURE__ */ React.createElement("h1", { className: "text-3xl font-semibold" }, t("Verify email")), /* @__PURE__ */ React.createElement("p", { className: "text-muted-foreground" }, t("We've sent a verification code to your email address: {email}", {
|
|
41
|
+
email
|
|
42
|
+
}))), /* @__PURE__ */ React.createElement("div", { className: "grid gap-6" }, generalError && /* @__PURE__ */ React.createElement("div", { className: "flex gap-2 p-3 bg-red-50 border border-red-200 rounded-lg" }, /* @__PURE__ */ React.createElement(AlertCircle, { className: "w-4 h-4 text-red-600 flex-shrink-0 mt-0.5" }), /* @__PURE__ */ React.createElement("p", { className: "text-sm text-red-600" }, generalError)), /* @__PURE__ */ React.createElement("form", { onSubmit: form.handleSubmit(onSubmit), className: "grid gap-5" }, /* @__PURE__ */ React.createElement(FieldGroup, { className: "w-full mx-auto" }, /* @__PURE__ */ React.createElement(
|
|
43
|
+
Controller,
|
|
44
|
+
{
|
|
45
|
+
name: "code",
|
|
46
|
+
control: form.control,
|
|
47
|
+
render: ({ field, fieldState }) => /* @__PURE__ */ React.createElement(Field, { className: "w-full", "data-invalid": fieldState.invalid }, /* @__PURE__ */ React.createElement(
|
|
48
|
+
InputOTP,
|
|
49
|
+
{
|
|
50
|
+
...field,
|
|
51
|
+
className: "mx-auto w-full",
|
|
52
|
+
maxLength: 6,
|
|
53
|
+
autoFocus: true,
|
|
54
|
+
inputMode: "text"
|
|
55
|
+
},
|
|
56
|
+
/* @__PURE__ */ React.createElement(InputOTPGroup, { className: "mx-auto" }, /* @__PURE__ */ React.createElement(InputOTPSlot, { index: 0 }), /* @__PURE__ */ React.createElement(InputOTPSlot, { index: 1 }), /* @__PURE__ */ React.createElement(InputOTPSlot, { index: 2 }), /* @__PURE__ */ React.createElement(InputOTPSlot, { index: 3 }), /* @__PURE__ */ React.createElement(InputOTPSlot, { index: 4 }), /* @__PURE__ */ React.createElement(InputOTPSlot, { index: 5 }))
|
|
57
|
+
), fieldState.invalid && /* @__PURE__ */ React.createElement(FieldError, { errors: [fieldState.error] }))
|
|
58
|
+
}
|
|
59
|
+
)), /* @__PURE__ */ React.createElement(Button, { disabled: form.formState.isSubmitting, className: "w-full" }, form.formState.isSubmitting ? t("Please wait...") : t("Verify Email"), form.formState.isSubmitting && /* @__PURE__ */ React.createElement(Loader, { variant: "dark" })))));
|
|
60
|
+
}
|
|
61
|
+
const resendEmailInitialState = {
|
|
62
|
+
message: ""
|
|
63
|
+
};
|
|
64
|
+
export function ResendEmailVerificationCodeForm() {
|
|
65
|
+
const { t } = useTranslation();
|
|
66
|
+
const [state, action, isPending] = useActionState(
|
|
67
|
+
resendEmailVerificationCodeAction,
|
|
68
|
+
resendEmailInitialState
|
|
69
|
+
);
|
|
70
|
+
useEffect(() => {
|
|
71
|
+
if (state.message) {
|
|
72
|
+
toast.success(state.message);
|
|
73
|
+
}
|
|
74
|
+
}, [state]);
|
|
75
|
+
return /* @__PURE__ */ React.createElement("form", { action }, /* @__PURE__ */ React.createElement(Button, { disabled: isPending, variant: "ghost", className: "w-full" }, isPending ? t("Please wait...") : t("Resend verification email"), isPending && /* @__PURE__ */ React.createElement(Loader, { variant: "default" })));
|
|
76
|
+
}
|