@sqrzro/auth 4.0.0-alpha.1 → 4.0.0-alpha.10
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 +580 -72
- package/dist/components/Auth/index.d.ts +5 -4
- package/dist/components/Auth/index.js +6 -6
- package/dist/components/Password/index.d.ts +4 -3
- package/dist/components/Password/index.js +4 -4
- 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/index.d.ts +2 -1
- package/dist/forms/LoginForm/index.js +2 -2
- package/dist/forms/LoginForm/server.js +6 -2
- package/dist/forms/PasswordForm/index.d.ts +7 -1
- package/dist/forms/PasswordForm/index.js +19 -4
- package/dist/forms/PasswordForm/server.js +9 -6
- package/dist/forms/PasswordResetForm/index.d.ts +3 -2
- package/dist/forms/PasswordResetForm/index.js +6 -4
- 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 +6 -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 +5 -4
- package/src/components/Auth/index.tsx +18 -13
- package/src/components/Password/index.tsx +12 -7
- package/src/components/PasswordComplexityFormField/index.tsx +34 -0
- package/src/forms/LoginForm/index.tsx +10 -4
- package/src/forms/LoginForm/server.ts +11 -3
- package/src/forms/PasswordForm/index.tsx +88 -8
- package/src/forms/PasswordForm/server.ts +13 -7
- package/src/forms/PasswordResetForm/index.tsx +17 -6
- 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 +9 -1
- 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
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { PasswordComplexityObject } from './interfaces';
|
|
2
|
+
|
|
3
|
+
const DEFAULT_COMPLEXITY: PasswordComplexityObject = {
|
|
4
|
+
LENGTH: 8,
|
|
5
|
+
LOWERCASE: 1,
|
|
6
|
+
UPPERCASE: 1,
|
|
7
|
+
NUMBER: 1,
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
function getComplexity(complexity?: PasswordComplexityObject): PasswordComplexityObject {
|
|
11
|
+
return complexity ?? DEFAULT_COMPLEXITY;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export default getComplexity;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export enum PasswordComplexityKey {
|
|
2
|
+
LENGTH = 'LENGTH',
|
|
3
|
+
UPPERCASE = 'UPPERCASE',
|
|
4
|
+
LOWERCASE = 'LOWERCASE',
|
|
5
|
+
NUMBER = 'NUMBER',
|
|
6
|
+
SPECIAL = 'SPECIAL',
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export type PasswordComplexityObject = Partial<Record<PasswordComplexityKey, number>>;
|
|
10
|
+
|
|
11
|
+
export type PasswordComplexityResult = { status: boolean; value: string }[];
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { formatPlural } from '@sqrzro/utility';
|
|
2
|
+
|
|
3
|
+
import { PasswordComplexityKey } from './interfaces';
|
|
4
|
+
|
|
5
|
+
export const complexities: Record<PasswordComplexityKey, (value?: number) => string> = {
|
|
6
|
+
[PasswordComplexityKey.LENGTH]: (value) => `At least ${formatPlural('character', value)} long`,
|
|
7
|
+
[PasswordComplexityKey.UPPERCASE]: (value) =>
|
|
8
|
+
`Contain at least ${formatPlural('uppercase letter', value)}`,
|
|
9
|
+
[PasswordComplexityKey.LOWERCASE]: (value) =>
|
|
10
|
+
`Contain at least ${formatPlural('lowercase letter', value)}`,
|
|
11
|
+
[PasswordComplexityKey.NUMBER]: (value) => `Contain at least ${formatPlural('number', value)}`,
|
|
12
|
+
[PasswordComplexityKey.SPECIAL]: (value) =>
|
|
13
|
+
`Contain at least ${formatPlural('special character', value)}`,
|
|
14
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { getEntries, getKeys } from '@sqrzro/utility';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
import createComplexitySchema from './create-complexity-schema';
|
|
5
|
+
import { complexities } from './lang';
|
|
6
|
+
|
|
7
|
+
import { PasswordComplexityKey } from './interfaces';
|
|
8
|
+
import type { PasswordComplexityObject, PasswordComplexityResult } from './interfaces';
|
|
9
|
+
|
|
10
|
+
function getDefaultComplexityResult(
|
|
11
|
+
complexity: PasswordComplexityObject
|
|
12
|
+
): PasswordComplexityResult {
|
|
13
|
+
return getEntries(complexity).map(([key, value]) => ({
|
|
14
|
+
status: false,
|
|
15
|
+
value: complexities[key](value),
|
|
16
|
+
}));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function transformResult(
|
|
20
|
+
complexity: PasswordComplexityObject,
|
|
21
|
+
errors: PasswordComplexityKey[]
|
|
22
|
+
): PasswordComplexityResult {
|
|
23
|
+
// If there are errors that don't match the complexity keys (for example, the initial state), return the default result
|
|
24
|
+
|
|
25
|
+
if (errors.find((error) => !getKeys(complexity).includes(error))) {
|
|
26
|
+
return getDefaultComplexityResult(complexity);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return getEntries(complexity).map(([key, value]) => ({
|
|
30
|
+
status: !errors.includes(key),
|
|
31
|
+
value: complexities[key](value),
|
|
32
|
+
}));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function validateComplexity(
|
|
36
|
+
complexity: PasswordComplexityObject,
|
|
37
|
+
password?: string
|
|
38
|
+
): PasswordComplexityResult {
|
|
39
|
+
try {
|
|
40
|
+
createComplexitySchema(complexity).parse(password);
|
|
41
|
+
return transformResult(complexity, []);
|
|
42
|
+
} catch (error) {
|
|
43
|
+
if (error instanceof z.ZodError) {
|
|
44
|
+
return transformResult(
|
|
45
|
+
complexity,
|
|
46
|
+
error.issues.map((issue) => issue.message as PasswordComplexityKey)
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
return getDefaultComplexityResult(complexity);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export default validateComplexity;
|
package/src/handle-proxy.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { validateSession } from '@sqrzro/server/auth';
|
|
2
|
-
import { NextResponse } from 'next/server';
|
|
3
|
-
import type { NextRequest } from 'next/server';
|
|
4
|
-
|
|
5
|
-
async function handleProxy(request: NextRequest): Promise<NextResponse> {
|
|
6
|
-
const pathname = request.nextUrl.pathname;
|
|
7
|
-
const validated = await validateSession(request.cookies);
|
|
8
|
-
|
|
9
|
-
if (validated) {
|
|
10
|
-
if (pathname.startsWith('/auth')) {
|
|
11
|
-
return NextResponse.redirect(new URL('/', request.url));
|
|
12
|
-
}
|
|
13
|
-
return NextResponse.next();
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
if (pathname.startsWith('/auth')) {
|
|
17
|
-
return NextResponse.next();
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return NextResponse.redirect(new URL('/auth/login', request.url));
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export default handleProxy;
|