@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.
Files changed (64) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/.turbo/turbo-dev.log +32 -18
  3. package/dist/components/Auth/index.d.ts +2 -2
  4. package/dist/components/Password/index.d.ts +2 -2
  5. package/dist/components/Password/index.js +1 -1
  6. package/dist/components/PasswordComplexityFormField/index.d.ts +8 -0
  7. package/dist/components/PasswordComplexityFormField/index.js +10 -0
  8. package/dist/components/PasswordComplexityInput/index.d.ts +5 -0
  9. package/dist/components/PasswordComplexityInput/index.js +9 -0
  10. package/dist/extend-repository.d.ts +0 -0
  11. package/dist/extend-repository.js +1 -0
  12. package/dist/forms/LoginForm/server.js +2 -2
  13. package/dist/forms/PasswordForm/index.d.ts +6 -1
  14. package/dist/forms/PasswordForm/index.js +19 -4
  15. package/dist/forms/PasswordForm/server.js +9 -6
  16. package/dist/forms/PasswordResetForm/index.js +5 -3
  17. package/dist/forms/PasswordResetForm/server.js +10 -7
  18. package/dist/get-auth-proxy.d.ts +6 -0
  19. package/dist/get-auth-proxy.js +17 -0
  20. package/dist/handle-auth-proxy.d.ts +5 -0
  21. package/dist/handle-auth-proxy.js +14 -0
  22. package/dist/index.d.ts +3 -1
  23. package/dist/index.js +1 -1
  24. package/dist/interfaces.d.ts +3 -0
  25. package/dist/mail/PasswordMail.d.ts +5 -0
  26. package/dist/mail/PasswordMail.js +6 -0
  27. package/dist/rules/complexity.d.ts +4 -0
  28. package/dist/rules/complexity.js +9 -0
  29. package/dist/rules/password.d.ts +3 -0
  30. package/dist/rules/password.js +6 -0
  31. package/dist/utility/create-complexity-schema.d.ts +4 -0
  32. package/dist/utility/create-complexity-schema.js +22 -0
  33. package/dist/utility/create-password-schema.d.ts +0 -0
  34. package/dist/utility/create-password-schema.js +1 -0
  35. package/dist/utility/get-complexity.d.ts +3 -0
  36. package/dist/utility/get-complexity.js +10 -0
  37. package/dist/utility/interfaces.d.ts +12 -0
  38. package/dist/utility/interfaces.js +8 -0
  39. package/dist/utility/lang.d.ts +2 -0
  40. package/dist/utility/lang.js +9 -0
  41. package/dist/utility/validate-complexity.d.ts +3 -0
  42. package/dist/utility/validate-complexity.js +33 -0
  43. package/dist/utility/validate-password-complexity.d.ts +14 -0
  44. package/dist/utility/validate-password-complexity.js +65 -0
  45. package/package.json +4 -3
  46. package/src/components/Auth/index.tsx +3 -3
  47. package/src/components/Password/index.tsx +5 -4
  48. package/src/components/PasswordComplexityFormField/index.tsx +34 -0
  49. package/src/forms/LoginForm/server.ts +3 -3
  50. package/src/forms/PasswordForm/index.tsx +86 -8
  51. package/src/forms/PasswordForm/server.ts +13 -7
  52. package/src/forms/PasswordResetForm/index.tsx +10 -4
  53. package/src/forms/PasswordResetForm/server.ts +12 -8
  54. package/src/get-auth-proxy.ts +34 -0
  55. package/src/index.ts +5 -1
  56. package/src/interfaces.ts +4 -0
  57. package/src/mail/PasswordMail.tsx +16 -0
  58. package/src/rules/complexity.ts +14 -0
  59. package/src/utility/create-complexity-schema.ts +44 -0
  60. package/src/utility/get-complexity.ts +14 -0
  61. package/src/utility/interfaces.ts +11 -0
  62. package/src/utility/lang.ts +14 -0
  63. package/src/utility/validate-complexity.ts +53 -0
  64. package/src/handle-proxy.ts +0 -23
@@ -1,5 +1,5 @@
1
1
 
2
2
  
3
- > @sqrzro/auth@4.0.0-alpha.5 build /Users/richard/Sites/@sqrzro/sqrzro/packages/auth
3
+ > @sqrzro/auth@4.0.0-alpha.8 build /Users/richard/Sites/@sqrzro/sqrzro/packages/auth
4
4
  > tsc
5
5
 
@@ -1,12 +1,12 @@
1
1
 
2
- > @sqrzro/auth@4.0.0-alpha.5 dev /Users/richard/Sites/@sqrzro/sqrzro/packages/auth
2
+ > @sqrzro/auth@4.0.0-alpha.8 dev /Users/richard/Sites/@sqrzro/sqrzro/packages/auth
3
3
  > tsc --watch
4
4
 
5
- [2:01:09 PM] Starting compilation in watch mode...
5
+ [3:09:10 PM] Starting compilation in watch mode...
6
6
 
7
- [2:01:11 PM] Found 0 errors. Watching for file changes.
7
+ [3:09:12 PM] Found 0 errors. Watching for file changes.
8
8
 
9
- [2:01:13 PM] File change detected. Starting incremental compilation...
9
+ [3:09:16 PM] File change detected. Starting incremental compilation...
10
10
 
11
11
  src/components/LogoutButton/server.ts:3:31 - error TS7016: Could 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
  4 import { FormResponse, submitForm } from '@sqrzro/server/forms';
51
51
     ~~~~~~~~~~~~~~~~~~~~~~
52
52
 
53
+ src/forms/PasswordForm/server.ts:5:26 - error TS7016: Could 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
+ 5 import { sendMail } from '@sqrzro/server/mail';
57
+    ~~~~~~~~~~~~~~~~~~~~~
58
+
53
59
  src/forms/PasswordResetForm/server.ts:3:41 - error TS7016: Could 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
  4 import { FormResponse, submitForm } from '@sqrzro/server/forms';
63
69
     ~~~~~~~~~~~~~~~~~~~~~~
64
70
 
65
- src/handle-proxy.ts:1:33 - error TS7016: Could 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.
71
+ src/get-auth-proxy.ts:1:34 - error TS7016: Could 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
- 1 import { validateSession } from '@sqrzro/server/auth';
69
-    ~~~~~~~~~~~~~~~~~~~~~
74
+ 1 import type { AuthSession } from '@sqrzro/server/auth';
75
+    ~~~~~~~~~~~~~~~~~~~~~
76
+
77
+ src/get-auth-proxy.ts:2:36 - error TS7016: Could 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
+ 2 import type { ProxyRedirect } from '@sqrzro/server/proxy';
81
+    ~~~~~~~~~~~~~~~~~~~~~~
70
82
 
71
- [2:01:13 PM] Found 10 errors. Watching for file changes.
83
+ src/mail/PasswordMail.tsx:1:28 - error TS7016: Could 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
- [2:01:16 PM] File change detected. Starting incremental compilation...
86
+ 1 import { createMail } from '@sqrzro/server/mail';
87
+    ~~~~~~~~~~~~~~~~~~~~~
74
88
 
75
- [2:01:16 PM] Found 0 errors. Watching for file changes.
89
+ [3:09:16 PM] Found 13 errors. Watching for file changes.
76
90
 
77
- [2:13:49 PM] File change detected. Starting incremental compilation...
91
+ [3:09:20 PM] File change detected. Starting incremental compilation...
78
92
 
79
- [2:13:50 PM] Found 0 errors. Watching for file changes.
93
+ [3:09:20 PM] Found 0 errors. Watching for file changes.
80
94
 
81
- [2:13:50 PM] File change detected. Starting incremental compilation...
95
+ [4:40:34 PM] File change detected. Starting incremental compilation...
82
96
 
83
- [2:13:50 PM] Found 0 errors. Watching for file changes.
97
+ [4:40:34 PM] Found 0 errors. Watching for file changes.
84
98
 
85
- [2:21:47 PM] File change detected. Starting incremental compilation...
99
+ [4:40:39 PM] File change detected. Starting incremental compilation...
86
100
 
87
- [2:21:47 PM] Found 0 errors. Watching for file changes.
101
+ [4:40:39 PM] Found 0 errors. Watching for file changes.
88
102
 
89
- [2:21:49 PM] File change detected. Starting incremental compilation...
103
+ [4:40:45 PM] File change detected. Starting incremental compilation...
90
104
 
91
- [2:21:49 PM] Found 0 errors. Watching for file changes.
105
+ [4:40:45 PM] Found 0 errors. Watching for file changes.
92
106
 
93
107
   ELIFECYCLE  Command failed.
@@ -1,7 +1,7 @@
1
1
  import type { NextPageProps } from '@sqrzro/ui/utility';
2
2
  import type { AuthClassNameProps } from '../../interfaces';
3
- interface AuthPageProps extends AuthClassNameProps, NextPageProps {
3
+ export interface AuthProps extends AuthClassNameProps, NextPageProps {
4
4
  logo?: React.ReactElement;
5
5
  }
6
- declare function Auth({ classNames, logo, ...props }: AuthPageProps): React.ReactElement;
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
- declare function PasswordForm({ classNames }: AuthClassNameProps): React.ReactElement | null;
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 { fieldProps, formProps } = useForm({
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
- return (_jsx(Fragment, { children: _jsxs(Form, { ...formProps, children: [_jsx(TextFormField, { ...fieldProps('email'), hasAssistiveError: true }), _jsx(FormSubmit, { isFullWidth: true, children: "Send Email" })] }) }));
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
- const schema = z
6
- .object({
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
- console.log(token);
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, PasswordFormField, useForm } from '@sqrzro/ui/forms';
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(PasswordFormField, { ...fieldProps('password') }), _jsx(FormSubmit, { isFullWidth: true, children: "Reset Password" })] }) }));
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
- const schema = z
7
- .object({
8
- password: z.string(),
9
- token: z.string().regex(/[A-Za-z0-9]{48}/u),
10
- })
11
- .required({ password: true, token: true });
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 handleProxy } from './handle-proxy';
5
+ export { default as getAuthProxy } from './get-auth-proxy';
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
1
  export { default as Auth } from './components/Auth';
2
2
  export { default as LogoutButton } from './components/LogoutButton';
3
- export { default as handleProxy } from './handle-proxy';
3
+ export { default as getAuthProxy } from './get-auth-proxy';
@@ -1,3 +1,6 @@
1
+ export interface AuthConfigObject {
2
+ allow?: string[];
3
+ }
1
4
  export interface AuthClassNames {
2
5
  actions: string;
3
6
  footer: string;
@@ -0,0 +1,5 @@
1
+ interface PasswordMailProps {
2
+ readonly token: string;
3
+ }
4
+ declare const _default: import("@sqrzro/server/mail").MailObject<PasswordMailProps>;
5
+ export default _default;
@@ -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,4 @@
1
+ import { z } from 'zod';
2
+ import type { PasswordComplexityObject } from '../utility/interfaces';
3
+ declare function getComplexityRule(complexity: PasswordComplexityObject): z.ZodString;
4
+ export default getComplexityRule;
@@ -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,3 @@
1
+ import type { PasswordComplexityObject } from '../utility/interfaces';
2
+ declare function getPasswordComplexityRule(complexity: PasswordComplexityObject): import("zod").ZodString;
3
+ export default getPasswordComplexityRule;
@@ -0,0 +1,6 @@
1
+ import createComplexitySchema from '../utility/create-complexity-schema';
2
+ function getPasswordComplexityRule(complexity) {
3
+ const schema = createComplexitySchema(complexity);
4
+ return schema;
5
+ }
6
+ export default getPasswordComplexityRule;
@@ -0,0 +1,4 @@
1
+ import { z } from 'zod';
2
+ import type { PasswordComplexityObject } from './interfaces';
3
+ declare function createComplexitySchema(complexity: PasswordComplexityObject): z.ZodString;
4
+ export default createComplexitySchema;
@@ -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,3 @@
1
+ import type { PasswordComplexityObject } from './interfaces';
2
+ declare function getComplexity(complexity?: PasswordComplexityObject): PasswordComplexityObject;
3
+ export default getComplexity;
@@ -0,0 +1,10 @@
1
+ const DEFAULT_COMPLEXITY = {
2
+ LENGTH: 8,
3
+ LOWERCASE: 1,
4
+ UPPERCASE: 1,
5
+ NUMBER: 1,
6
+ };
7
+ function getComplexity(complexity) {
8
+ return complexity ?? DEFAULT_COMPLEXITY;
9
+ }
10
+ export default getComplexity;
@@ -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,2 @@
1
+ import { PasswordComplexityKey } from './interfaces';
2
+ export declare const complexities: Record<PasswordComplexityKey, (value?: number) => string>;
@@ -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,3 @@
1
+ import type { PasswordComplexityObject, PasswordComplexityResult } from './interfaces';
2
+ declare function validateComplexity(complexity: PasswordComplexityObject, password?: string): PasswordComplexityResult;
3
+ export default validateComplexity;
@@ -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;