@sqrzro/auth 4.0.0-alpha.7 → 4.0.0-alpha.9
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/.turbo/turbo-build.log +1 -1
- package/.turbo/turbo-dev.log +32 -18
- package/dist/components/Auth/index.d.ts +2 -2
- package/dist/components/Password/index.d.ts +2 -2
- package/dist/components/Password/index.js +1 -1
- package/dist/components/PasswordComplexityFormField/index.d.ts +8 -0
- package/dist/components/PasswordComplexityFormField/index.js +10 -0
- package/dist/components/PasswordComplexityInput/index.d.ts +5 -0
- package/dist/components/PasswordComplexityInput/index.js +9 -0
- package/dist/extend-repository.d.ts +0 -0
- package/dist/extend-repository.js +1 -0
- package/dist/forms/LoginForm/server.js +2 -2
- package/dist/forms/PasswordForm/index.d.ts +6 -1
- package/dist/forms/PasswordForm/index.js +19 -4
- package/dist/forms/PasswordForm/server.js +9 -6
- package/dist/forms/PasswordResetForm/index.js +5 -3
- package/dist/forms/PasswordResetForm/server.js +10 -7
- package/dist/get-auth-proxy.d.ts +6 -0
- package/dist/get-auth-proxy.js +17 -0
- package/dist/handle-auth-proxy.d.ts +5 -0
- package/dist/handle-auth-proxy.js +14 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +1 -1
- package/dist/interfaces.d.ts +3 -0
- package/dist/mail/PasswordMail.d.ts +5 -0
- package/dist/mail/PasswordMail.js +6 -0
- package/dist/rules/complexity.d.ts +4 -0
- package/dist/rules/complexity.js +9 -0
- package/dist/rules/password.d.ts +3 -0
- package/dist/rules/password.js +6 -0
- package/dist/utility/create-complexity-schema.d.ts +4 -0
- package/dist/utility/create-complexity-schema.js +22 -0
- package/dist/utility/create-password-schema.d.ts +0 -0
- package/dist/utility/create-password-schema.js +1 -0
- package/dist/utility/get-complexity.d.ts +3 -0
- package/dist/utility/get-complexity.js +10 -0
- package/dist/utility/interfaces.d.ts +12 -0
- package/dist/utility/interfaces.js +8 -0
- package/dist/utility/lang.d.ts +2 -0
- package/dist/utility/lang.js +9 -0
- package/dist/utility/validate-complexity.d.ts +3 -0
- package/dist/utility/validate-complexity.js +33 -0
- package/dist/utility/validate-password-complexity.d.ts +14 -0
- package/dist/utility/validate-password-complexity.js +65 -0
- package/package.json +4 -3
- package/src/components/Auth/index.tsx +3 -3
- package/src/components/Password/index.tsx +5 -4
- package/src/components/PasswordComplexityFormField/index.tsx +34 -0
- package/src/forms/LoginForm/server.ts +3 -3
- package/src/forms/PasswordForm/index.tsx +86 -8
- package/src/forms/PasswordForm/server.ts +13 -7
- package/src/forms/PasswordResetForm/index.tsx +10 -4
- package/src/forms/PasswordResetForm/server.ts +12 -8
- package/src/get-auth-proxy.ts +34 -0
- package/src/index.ts +5 -1
- package/src/interfaces.ts +4 -0
- package/src/mail/PasswordMail.tsx +16 -0
- package/src/rules/complexity.ts +14 -0
- package/src/utility/create-complexity-schema.ts +44 -0
- package/src/utility/get-complexity.ts +14 -0
- package/src/utility/interfaces.ts +11 -0
- package/src/utility/lang.ts +14 -0
- package/src/utility/validate-complexity.ts +53 -0
- package/src/handle-proxy.ts +0 -23
package/.turbo/turbo-build.log
CHANGED
package/.turbo/turbo-dev.log
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
|
|
2
|
-
> @sqrzro/auth@4.0.0-alpha.
|
|
2
|
+
> @sqrzro/auth@4.0.0-alpha.8 dev /Users/richard/Sites/@sqrzro/sqrzro/packages/auth
|
|
3
3
|
> tsc --watch
|
|
4
4
|
|
|
5
|
-
[2J[3J[H[[
|
|
5
|
+
[2J[3J[H[[90m3:09:10 PM[0m] Starting compilation in watch mode...
|
|
6
6
|
|
|
7
|
-
[[
|
|
7
|
+
[[90m3:09:12 PM[0m] Found 0 errors. Watching for file changes.
|
|
8
8
|
|
|
9
|
-
[2J[3J[H[[
|
|
9
|
+
[2J[3J[H[[90m3:09:16 PM[0m] File change detected. Starting incremental compilation...
|
|
10
10
|
|
|
11
11
|
[96msrc/components/LogoutButton/server.ts[0m:[93m3[0m:[93m31[0m - [91merror[0m[90m TS7016: [0mCould not find a declaration file for module '@sqrzro/server/auth'. '/Users/richard/Sites/@sqrzro/sqrzro/packages/server/dist/auth/index.js' implicitly has an 'any' type.
|
|
12
12
|
Try `npm i --save-dev @types/sqrzro__server` if it exists or add a new declaration (.d.ts) file containing `declare module '@sqrzro/server/auth';`
|
|
@@ -50,6 +50,12 @@
|
|
|
50
50
|
[7m4[0m import { FormResponse, submitForm } from '@sqrzro/server/forms';
|
|
51
51
|
[7m [0m [91m ~~~~~~~~~~~~~~~~~~~~~~[0m
|
|
52
52
|
|
|
53
|
+
[96msrc/forms/PasswordForm/server.ts[0m:[93m5[0m:[93m26[0m - [91merror[0m[90m TS7016: [0mCould not find a declaration file for module '@sqrzro/server/mail'. '/Users/richard/Sites/@sqrzro/sqrzro/packages/server/dist/mail/index.js' implicitly has an 'any' type.
|
|
54
|
+
Try `npm i --save-dev @types/sqrzro__server` if it exists or add a new declaration (.d.ts) file containing `declare module '@sqrzro/server/mail';`
|
|
55
|
+
|
|
56
|
+
[7m5[0m import { sendMail } from '@sqrzro/server/mail';
|
|
57
|
+
[7m [0m [91m ~~~~~~~~~~~~~~~~~~~~~[0m
|
|
58
|
+
|
|
53
59
|
[96msrc/forms/PasswordResetForm/server.ts[0m:[93m3[0m:[93m41[0m - [91merror[0m[90m TS7016: [0mCould not find a declaration file for module '@sqrzro/server/auth'. '/Users/richard/Sites/@sqrzro/sqrzro/packages/server/dist/auth/index.js' implicitly has an 'any' type.
|
|
54
60
|
Try `npm i --save-dev @types/sqrzro__server` if it exists or add a new declaration (.d.ts) file containing `declare module '@sqrzro/server/auth';`
|
|
55
61
|
|
|
@@ -62,32 +68,40 @@
|
|
|
62
68
|
[7m4[0m import { FormResponse, submitForm } from '@sqrzro/server/forms';
|
|
63
69
|
[7m [0m [91m ~~~~~~~~~~~~~~~~~~~~~~[0m
|
|
64
70
|
|
|
65
|
-
[96msrc/
|
|
71
|
+
[96msrc/get-auth-proxy.ts[0m:[93m1[0m:[93m34[0m - [91merror[0m[90m TS7016: [0mCould not find a declaration file for module '@sqrzro/server/auth'. '/Users/richard/Sites/@sqrzro/sqrzro/packages/server/dist/auth/index.js' implicitly has an 'any' type.
|
|
66
72
|
Try `npm i --save-dev @types/sqrzro__server` if it exists or add a new declaration (.d.ts) file containing `declare module '@sqrzro/server/auth';`
|
|
67
73
|
|
|
68
|
-
[7m1[0m import {
|
|
69
|
-
[7m [0m [91m
|
|
74
|
+
[7m1[0m import type { AuthSession } from '@sqrzro/server/auth';
|
|
75
|
+
[7m [0m [91m ~~~~~~~~~~~~~~~~~~~~~[0m
|
|
76
|
+
|
|
77
|
+
[96msrc/get-auth-proxy.ts[0m:[93m2[0m:[93m36[0m - [91merror[0m[90m TS7016: [0mCould not find a declaration file for module '@sqrzro/server/proxy'. '/Users/richard/Sites/@sqrzro/sqrzro/packages/server/dist/proxy/index.js' implicitly has an 'any' type.
|
|
78
|
+
Try `npm i --save-dev @types/sqrzro__server` if it exists or add a new declaration (.d.ts) file containing `declare module '@sqrzro/server/proxy';`
|
|
79
|
+
|
|
80
|
+
[7m2[0m import type { ProxyRedirect } from '@sqrzro/server/proxy';
|
|
81
|
+
[7m [0m [91m ~~~~~~~~~~~~~~~~~~~~~~[0m
|
|
70
82
|
|
|
71
|
-
[[
|
|
83
|
+
[96msrc/mail/PasswordMail.tsx[0m:[93m1[0m:[93m28[0m - [91merror[0m[90m TS7016: [0mCould not find a declaration file for module '@sqrzro/server/mail'. '/Users/richard/Sites/@sqrzro/sqrzro/packages/server/dist/mail/index.js' implicitly has an 'any' type.
|
|
84
|
+
Try `npm i --save-dev @types/sqrzro__server` if it exists or add a new declaration (.d.ts) file containing `declare module '@sqrzro/server/mail';`
|
|
72
85
|
|
|
73
|
-
[
|
|
86
|
+
[7m1[0m import { createMail } from '@sqrzro/server/mail';
|
|
87
|
+
[7m [0m [91m ~~~~~~~~~~~~~~~~~~~~~[0m
|
|
74
88
|
|
|
75
|
-
[[
|
|
89
|
+
[[90m3:09:16 PM[0m] Found 13 errors. Watching for file changes.
|
|
76
90
|
|
|
77
|
-
[2J[3J[H[[
|
|
91
|
+
[2J[3J[H[[90m3:09:20 PM[0m] File change detected. Starting incremental compilation...
|
|
78
92
|
|
|
79
|
-
[[
|
|
93
|
+
[[90m3:09:20 PM[0m] Found 0 errors. Watching for file changes.
|
|
80
94
|
|
|
81
|
-
[2J[3J[H[[
|
|
95
|
+
[2J[3J[H[[90m4:40:34 PM[0m] File change detected. Starting incremental compilation...
|
|
82
96
|
|
|
83
|
-
[[
|
|
97
|
+
[[90m4:40:34 PM[0m] Found 0 errors. Watching for file changes.
|
|
84
98
|
|
|
85
|
-
[2J[3J[H[[
|
|
99
|
+
[2J[3J[H[[90m4:40:39 PM[0m] File change detected. Starting incremental compilation...
|
|
86
100
|
|
|
87
|
-
[[
|
|
101
|
+
[[90m4:40:39 PM[0m] Found 0 errors. Watching for file changes.
|
|
88
102
|
|
|
89
|
-
[2J[3J[H[[
|
|
103
|
+
[2J[3J[H[[90m4:40:45 PM[0m] File change detected. Starting incremental compilation...
|
|
90
104
|
|
|
91
|
-
[[
|
|
105
|
+
[[90m4:40:45 PM[0m] Found 0 errors. Watching for file changes.
|
|
92
106
|
|
|
93
107
|
[41m[30m ELIFECYCLE [39m[49m [31mCommand failed.[39m
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { NextPageProps } from '@sqrzro/ui/utility';
|
|
2
2
|
import type { AuthClassNameProps } from '../../interfaces';
|
|
3
|
-
interface
|
|
3
|
+
export interface AuthProps extends AuthClassNameProps, NextPageProps {
|
|
4
4
|
logo?: React.ReactElement;
|
|
5
5
|
}
|
|
6
|
-
declare function Auth({ classNames, logo, ...props }:
|
|
6
|
+
declare function Auth({ classNames, logo, ...props }: AuthProps): React.ReactElement;
|
|
7
7
|
export default Auth;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { NextPageProps } from '@sqrzro/ui/utility';
|
|
1
2
|
import type { AuthClassNameProps } from '../../interfaces';
|
|
2
|
-
interface PasswordProps extends AuthClassNameProps {
|
|
3
|
-
searchParams?: Promise<Record<string, string>> | null;
|
|
3
|
+
interface PasswordProps extends AuthClassNameProps, NextPageProps {
|
|
4
4
|
}
|
|
5
5
|
declare function Password({ classNames, searchParams, }: Readonly<PasswordProps>): Promise<React.ReactElement>;
|
|
6
6
|
export default Password;
|
|
@@ -13,6 +13,6 @@ async function Password({ classNames, searchParams, }) {
|
|
|
13
13
|
return _jsx("div", { children: "Invalid or Expired Token" });
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
|
-
return _jsx(PasswordForm, { classNames: classNames });
|
|
16
|
+
return (_jsx(PasswordForm, { classNames: classNames, defaults: { email: awaitedSearchParams?.email } }));
|
|
17
17
|
}
|
|
18
18
|
export default Password;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { PasswordFormFieldProps } from '@sqrzro/ui/forms';
|
|
2
|
+
import type { PasswordComplexityObject } from '../../utility/interfaces';
|
|
3
|
+
interface PasswordComplexityFormFieldProps extends PasswordFormFieldProps {
|
|
4
|
+
complexity?: PasswordComplexityObject;
|
|
5
|
+
onComplexity?: (isValid: boolean) => void;
|
|
6
|
+
}
|
|
7
|
+
declare function PasswordComplexityFormField({ complexity, onComplexity, value, ...props }: PasswordComplexityFormFieldProps): React.ReactElement;
|
|
8
|
+
export default PasswordComplexityFormField;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Fragment } from 'react';
|
|
4
|
+
import { PasswordComplexity, PasswordFormField } from '@sqrzro/ui/forms';
|
|
5
|
+
import getComplexity from '../../utility/get-complexity';
|
|
6
|
+
import validatePasswordComplexity from '../../utility/validate-complexity';
|
|
7
|
+
function PasswordComplexityFormField({ complexity, onComplexity, value, ...props }) {
|
|
8
|
+
return (_jsxs(Fragment, { children: [_jsx(PasswordFormField, { value: value, ...props }), _jsx(PasswordComplexity, { data: validatePasswordComplexity(getComplexity(complexity), value), onComplexity: onComplexity })] }));
|
|
9
|
+
}
|
|
10
|
+
export default PasswordComplexityFormField;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { PasswordInputProps } from '@sqrzro/ui/forms';
|
|
2
|
+
interface PasswordComplexityInputProps extends PasswordInputProps {
|
|
3
|
+
}
|
|
4
|
+
declare function PasswordComplexityInput({ value, ...props }: PasswordComplexityInputProps): React.ReactElement;
|
|
5
|
+
export default PasswordComplexityInput;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { PasswordComplexity, PasswordInput } from '@sqrzro/ui/forms';
|
|
4
|
+
import getComplexity from '../../utility/get-complexity';
|
|
5
|
+
import validatePasswordComplexity from '../../utility/validate-complexity';
|
|
6
|
+
function PasswordComplexityInput({ value, ...props }) {
|
|
7
|
+
return (_jsxs("div", { children: [_jsx(PasswordInput, { value: value, ...props }), _jsx(PasswordComplexity, { data: validatePasswordComplexity(getComplexity(), value) })] }));
|
|
8
|
+
}
|
|
9
|
+
export default PasswordComplexityInput;
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -6,8 +6,8 @@ import { redirect } from 'next/navigation';
|
|
|
6
6
|
import { z } from 'zod';
|
|
7
7
|
const schema = z
|
|
8
8
|
.object({
|
|
9
|
-
email: z.email(),
|
|
10
|
-
password: z.string(),
|
|
9
|
+
email: z.email().nonempty(),
|
|
10
|
+
password: z.string().nonempty(),
|
|
11
11
|
redirect: z.string().optional(),
|
|
12
12
|
})
|
|
13
13
|
.required({ email: true, password: true });
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import { Default } from '@sqrzro/ui/forms';
|
|
1
2
|
import type { AuthClassNameProps } from '../../interfaces';
|
|
2
|
-
|
|
3
|
+
import type { PasswordFormFields } from './interfaces';
|
|
4
|
+
interface PasswordFormProps extends AuthClassNameProps {
|
|
5
|
+
defaults?: Default<PasswordFormFields>;
|
|
6
|
+
}
|
|
7
|
+
declare function PasswordForm({ classNames, defaults }: PasswordFormProps): React.ReactElement | null;
|
|
3
8
|
export default PasswordForm;
|
|
@@ -1,12 +1,27 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { Fragment } from 'react';
|
|
3
|
+
import { Fragment, useState } from 'react';
|
|
4
|
+
import { Link } from '@sqrzro/ui/components';
|
|
4
5
|
import { Form, FormSubmit, TextFormField, useForm } from '@sqrzro/ui/forms';
|
|
5
6
|
import submit from './server';
|
|
6
|
-
function PasswordForm({ classNames }) {
|
|
7
|
-
const
|
|
7
|
+
function PasswordForm({ classNames, defaults }) {
|
|
8
|
+
const [sentCount, setSentCount] = useState(0);
|
|
9
|
+
const { fieldProps, formData, formProps, setFormData, submitForm } = useForm({
|
|
10
|
+
defaults,
|
|
8
11
|
onSubmit: submit,
|
|
12
|
+
onSuccess: () => {
|
|
13
|
+
setSentCount(sentCount + 1);
|
|
14
|
+
},
|
|
9
15
|
});
|
|
10
|
-
|
|
16
|
+
function handleResend(event) {
|
|
17
|
+
event.preventDefault();
|
|
18
|
+
submitForm();
|
|
19
|
+
}
|
|
20
|
+
function handleReset(event) {
|
|
21
|
+
event.preventDefault();
|
|
22
|
+
setFormData('email', '');
|
|
23
|
+
setSentCount(0);
|
|
24
|
+
}
|
|
25
|
+
return (_jsxs(Fragment, { children: [_jsx("div", { style: { display: sentCount === 0 ? 'block' : 'none' }, children: _jsxs(Form, { ...formProps, children: [_jsx("h1", { className: classNames?.title, children: "Reset Your Password" }), _jsx("p", { className: "text-sm", children: "Enter the email address associated with your account and we'll send you a link to reset your password." }), _jsx(TextFormField, { ...fieldProps('email'), hasAssistiveError: true }), _jsx("div", { className: classNames?.actions, children: _jsx(FormSubmit, { isFullWidth: true, children: "Send Email" }) }), _jsx("footer", { className: classNames?.footer, children: _jsx(Link, { className: classNames?.link, href: "/auth/login", children: "Back" }) })] }) }), _jsx("div", { style: { display: sentCount === 0 ? 'none' : 'block' }, children: _jsxs("div", { className: classNames?.form, children: [_jsx("h1", { className: classNames?.title, children: "Check Your Email" }), sentCount === 1 ? (_jsxs(Fragment, { children: [_jsxs("p", { className: "text-sm", children: ["If ", _jsx("strong", { children: formData.email }), " matches an email we have on file, then we've sent you an email containing further instructions for resetting your password."] }), _jsxs("p", { className: "text-sm", children: ["If you haven't received an email in 5 minutes, check your spam,", ' ', _jsx(Link, { className: classNames?.link, onClick: handleResend, children: "resend" }), ", or", ' ', _jsx(Link, { className: classNames?.link, onClick: handleReset, children: "try a different email address" }), "."] })] })) : (_jsxs(Fragment, { children: [_jsxs("p", { className: "text-sm", children: ["We've resent password reset instructions to", ' ', _jsx("strong", { children: formData.email }), ", if it is an email we have on file."] }), _jsxs("p", { className: "text-sm", children: ["Please check again. If you still haven't received an email,", ' ', _jsx(Link, { className: classNames?.link, onClick: handleReset, children: "try a different email address" }), "."] })] }))] }) })] }));
|
|
11
26
|
}
|
|
12
27
|
export default PasswordForm;
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
'use server';
|
|
2
2
|
import { createReset } from '@sqrzro/server/auth';
|
|
3
3
|
import { submitForm } from '@sqrzro/server/forms';
|
|
4
|
+
import { sendMail } from '@sqrzro/server/mail';
|
|
4
5
|
import { z } from 'zod';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
email: z.email(),
|
|
8
|
-
})
|
|
9
|
-
.required({ email: true });
|
|
6
|
+
import PasswordMail from '../../mail/PasswordMail';
|
|
7
|
+
const schema = z.object({
|
|
8
|
+
email: z.email().nonempty(),
|
|
9
|
+
});
|
|
10
10
|
async function fn(data) {
|
|
11
11
|
const token = await createReset('PASSWORD', data.email);
|
|
12
|
-
|
|
12
|
+
if (!token) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
await sendMail(data.email, PasswordMail, { token });
|
|
13
16
|
}
|
|
14
17
|
async function submit(formData) {
|
|
15
18
|
return submitForm({
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { Fragment } from 'react';
|
|
4
|
-
import { Form, FormSubmit,
|
|
3
|
+
import { Fragment, useState } from 'react';
|
|
4
|
+
import { Form, FormSubmit, useForm } from '@sqrzro/ui/forms';
|
|
5
|
+
import PasswordComplexityFormField from '../../components/PasswordComplexityFormField';
|
|
5
6
|
import submit from './server';
|
|
6
7
|
function PasswordResetForm({ classNames, token, }) {
|
|
8
|
+
const [isDisabled, setIsDisabled] = useState(true);
|
|
7
9
|
const { fieldProps, formProps } = useForm({
|
|
8
10
|
defaults: { token },
|
|
9
11
|
onSubmit: submit,
|
|
10
12
|
});
|
|
11
|
-
return (_jsx(Fragment, { children: _jsxs(Form, { ...formProps, children: [_jsx(
|
|
13
|
+
return (_jsx(Fragment, { children: _jsxs(Form, { ...formProps, children: [_jsx(PasswordComplexityFormField, { ...fieldProps('password'), onComplexity: (isValid) => setIsDisabled(!isValid) }), _jsx(FormSubmit, { isDisabled: isDisabled, children: "Reset Password" })] }) }));
|
|
12
14
|
}
|
|
13
15
|
export default PasswordResetForm;
|
|
@@ -3,14 +3,17 @@ import { updatePasswordWithToken } from '@sqrzro/server/auth';
|
|
|
3
3
|
import { submitForm } from '@sqrzro/server/forms';
|
|
4
4
|
import { redirect } from 'next/navigation';
|
|
5
5
|
import { z } from 'zod';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
import getComplexityRule from '../../rules/complexity';
|
|
7
|
+
import getComplexity from '../../utility/get-complexity';
|
|
8
|
+
const schema = z.object({
|
|
9
|
+
password: getComplexityRule(getComplexity()).nonempty(),
|
|
10
|
+
token: z
|
|
11
|
+
.string()
|
|
12
|
+
.regex(/[A-Za-z0-9]{48}/u)
|
|
13
|
+
.nonempty(),
|
|
14
|
+
});
|
|
12
15
|
async function fn(data) {
|
|
13
|
-
await updatePasswordWithToken(data.token, data.password);
|
|
16
|
+
await updatePasswordWithToken('PASSWORD', data.token, data.password);
|
|
14
17
|
return redirect('/auth/login');
|
|
15
18
|
}
|
|
16
19
|
async function submit(formData) {
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { AuthSession } from '@sqrzro/server/auth';
|
|
2
|
+
import type { ProxyRedirect } from '@sqrzro/server/proxy';
|
|
3
|
+
import type { NextRequest } from 'next/server';
|
|
4
|
+
import type { AuthConfigObject } from './interfaces';
|
|
5
|
+
declare function getAuthProxy(config?: AuthConfigObject): (session: AuthSession | null, request: NextRequest) => Promise<ProxyRedirect | null>;
|
|
6
|
+
export default getAuthProxy;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
async function handleAuthProxy(session, request, config) {
|
|
2
|
+
const pathname = request.nextUrl.pathname;
|
|
3
|
+
if (session) {
|
|
4
|
+
if (pathname.startsWith('/auth')) {
|
|
5
|
+
return { redirect: '/' };
|
|
6
|
+
}
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
if (pathname.startsWith('/auth') || config?.allow?.includes(pathname)) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
return { redirect: '/auth/login' };
|
|
13
|
+
}
|
|
14
|
+
function getAuthProxy(config) {
|
|
15
|
+
return (session, request) => handleAuthProxy(session, request, config);
|
|
16
|
+
}
|
|
17
|
+
export default getAuthProxy;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { AuthSession } from '@sqrzro/server/auth';
|
|
2
|
+
import type { ProxyRedirect } from '@sqrzro/server/proxy';
|
|
3
|
+
import type { NextRequest } from 'next/server';
|
|
4
|
+
declare function handleAuthProxy(session: AuthSession | null, request: NextRequest): Promise<ProxyRedirect | null>;
|
|
5
|
+
export default handleAuthProxy;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
async function handleAuthProxy(session, request) {
|
|
2
|
+
const pathname = request.nextUrl.pathname;
|
|
3
|
+
if (session) {
|
|
4
|
+
if (pathname.startsWith('/auth')) {
|
|
5
|
+
return { redirect: '/' };
|
|
6
|
+
}
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
if (pathname.startsWith('/auth')) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
return { redirect: '/auth/login' };
|
|
13
|
+
}
|
|
14
|
+
export default handleAuthProxy;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export type { AuthClassNames, AuthConfigObject } from './interfaces';
|
|
2
|
+
export type { AuthProps } from './components/Auth';
|
|
1
3
|
export { default as Auth } from './components/Auth';
|
|
2
4
|
export { default as LogoutButton } from './components/LogoutButton';
|
|
3
|
-
export { default as
|
|
5
|
+
export { default as getAuthProxy } from './get-auth-proxy';
|
package/dist/index.js
CHANGED
package/dist/interfaces.d.ts
CHANGED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { createMail } from '@sqrzro/server/mail';
|
|
3
|
+
function PasswordMail({ token }) {
|
|
4
|
+
return (_jsxs("div", { children: ["PasswordMail", _jsx("a", { href: `http://localhost:8000/auth/password?token=${token}`, children: "Reset Password" })] }));
|
|
5
|
+
}
|
|
6
|
+
export default createMail('PASSWORD', PasswordMail);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import createComplexitySchema from '../utility/create-complexity-schema';
|
|
3
|
+
function getComplexityRule(complexity) {
|
|
4
|
+
const schema = createComplexitySchema(complexity);
|
|
5
|
+
return z.string().refine((value) => schema.safeParse(value).success, {
|
|
6
|
+
message: 'Password does not meet complexity requirements',
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
export default getComplexityRule;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { PasswordComplexityKey } from './interfaces';
|
|
3
|
+
function createComplexitySchema(complexity) {
|
|
4
|
+
let result = z.string();
|
|
5
|
+
if (complexity.LENGTH) {
|
|
6
|
+
result = result.min(complexity.LENGTH, PasswordComplexityKey.LENGTH);
|
|
7
|
+
}
|
|
8
|
+
if (complexity.UPPERCASE) {
|
|
9
|
+
result = result.regex(new RegExp(`(?:.*[A-Z]){${complexity.UPPERCASE}}`), PasswordComplexityKey.UPPERCASE);
|
|
10
|
+
}
|
|
11
|
+
if (complexity.LOWERCASE) {
|
|
12
|
+
result = result.regex(new RegExp(`(?:.*[a-z]){${complexity.LOWERCASE}}`), PasswordComplexityKey.LOWERCASE);
|
|
13
|
+
}
|
|
14
|
+
if (complexity.NUMBER) {
|
|
15
|
+
result = result.regex(new RegExp(`(?:.*\\d){${complexity.NUMBER}}`), PasswordComplexityKey.NUMBER);
|
|
16
|
+
}
|
|
17
|
+
if (complexity.SPECIAL) {
|
|
18
|
+
result = result.regex(new RegExp(`(?:.*[@$!%*?&]){${complexity.SPECIAL}}`), PasswordComplexityKey.SPECIAL);
|
|
19
|
+
}
|
|
20
|
+
return result;
|
|
21
|
+
}
|
|
22
|
+
export default createComplexitySchema;
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare enum PasswordComplexityKey {
|
|
2
|
+
LENGTH = "LENGTH",
|
|
3
|
+
UPPERCASE = "UPPERCASE",
|
|
4
|
+
LOWERCASE = "LOWERCASE",
|
|
5
|
+
NUMBER = "NUMBER",
|
|
6
|
+
SPECIAL = "SPECIAL"
|
|
7
|
+
}
|
|
8
|
+
export type PasswordComplexityObject = Partial<Record<PasswordComplexityKey, number>>;
|
|
9
|
+
export type PasswordComplexityResult = {
|
|
10
|
+
status: boolean;
|
|
11
|
+
value: string;
|
|
12
|
+
}[];
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export var PasswordComplexityKey;
|
|
2
|
+
(function (PasswordComplexityKey) {
|
|
3
|
+
PasswordComplexityKey["LENGTH"] = "LENGTH";
|
|
4
|
+
PasswordComplexityKey["UPPERCASE"] = "UPPERCASE";
|
|
5
|
+
PasswordComplexityKey["LOWERCASE"] = "LOWERCASE";
|
|
6
|
+
PasswordComplexityKey["NUMBER"] = "NUMBER";
|
|
7
|
+
PasswordComplexityKey["SPECIAL"] = "SPECIAL";
|
|
8
|
+
})(PasswordComplexityKey || (PasswordComplexityKey = {}));
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { formatPlural } from '@sqrzro/utility';
|
|
2
|
+
import { PasswordComplexityKey } from './interfaces';
|
|
3
|
+
export const complexities = {
|
|
4
|
+
[PasswordComplexityKey.LENGTH]: (value) => `At least ${formatPlural('character', value)} long`,
|
|
5
|
+
[PasswordComplexityKey.UPPERCASE]: (value) => `Contain at least ${formatPlural('uppercase letter', value)}`,
|
|
6
|
+
[PasswordComplexityKey.LOWERCASE]: (value) => `Contain at least ${formatPlural('lowercase letter', value)}`,
|
|
7
|
+
[PasswordComplexityKey.NUMBER]: (value) => `Contain at least ${formatPlural('number', value)}`,
|
|
8
|
+
[PasswordComplexityKey.SPECIAL]: (value) => `Contain at least ${formatPlural('special character', value)}`,
|
|
9
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { getEntries, getKeys } from '@sqrzro/utility';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import createComplexitySchema from './create-complexity-schema';
|
|
4
|
+
import { complexities } from './lang';
|
|
5
|
+
function getDefaultComplexityResult(complexity) {
|
|
6
|
+
return getEntries(complexity).map(([key, value]) => ({
|
|
7
|
+
status: false,
|
|
8
|
+
value: complexities[key](value),
|
|
9
|
+
}));
|
|
10
|
+
}
|
|
11
|
+
function transformResult(complexity, errors) {
|
|
12
|
+
// If there are errors that don't match the complexity keys (for example, the initial state), return the default result
|
|
13
|
+
if (errors.find((error) => !getKeys(complexity).includes(error))) {
|
|
14
|
+
return getDefaultComplexityResult(complexity);
|
|
15
|
+
}
|
|
16
|
+
return getEntries(complexity).map(([key, value]) => ({
|
|
17
|
+
status: !errors.includes(key),
|
|
18
|
+
value: complexities[key](value),
|
|
19
|
+
}));
|
|
20
|
+
}
|
|
21
|
+
function validateComplexity(complexity, password) {
|
|
22
|
+
try {
|
|
23
|
+
createComplexitySchema(complexity).parse(password);
|
|
24
|
+
return transformResult(complexity, []);
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
if (error instanceof z.ZodError) {
|
|
28
|
+
return transformResult(complexity, error.issues.map((issue) => issue.message));
|
|
29
|
+
}
|
|
30
|
+
return getDefaultComplexityResult(complexity);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export default validateComplexity;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare enum PasswordComplexityKey {
|
|
2
|
+
LENGTH = "LENGTH",
|
|
3
|
+
UPPERCASE = "UPPERCASE",
|
|
4
|
+
LOWERCASE = "LOWERCASE",
|
|
5
|
+
NUMBER = "NUMBER",
|
|
6
|
+
SPECIAL = "SPECIAL"
|
|
7
|
+
}
|
|
8
|
+
export type PasswordComplexityObject = Partial<Record<PasswordComplexityKey, number>>;
|
|
9
|
+
type PasswordComplexityResult = {
|
|
10
|
+
status: boolean;
|
|
11
|
+
value: string;
|
|
12
|
+
}[];
|
|
13
|
+
declare function validatePasswordComplexity(complexity: PasswordComplexityObject, password?: string): PasswordComplexityResult;
|
|
14
|
+
export default validatePasswordComplexity;
|