@sqrzro/auth 4.0.0-alpha.7 → 4.0.0-alpha.8

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.
@@ -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
+ [2:49:05 PM] Starting compilation in watch mode...
6
6
 
7
- [2:01:11 PM] Found 0 errors. Watching for file changes.
7
+ [2:49:08 PM] Found 0 errors. Watching for file changes.
8
8
 
9
- [2:01:13 PM] File change detected. Starting incremental compilation...
9
+ [2:49:11 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';`
@@ -62,32 +62,62 @@
62
62
  4 import { FormResponse, submitForm } from '@sqrzro/server/forms';
63
63
     ~~~~~~~~~~~~~~~~~~~~~~
64
64
 
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.
65
+ 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
66
  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
67
 
68
- 1 import { validateSession } from '@sqrzro/server/auth';
69
-    ~~~~~~~~~~~~~~~~~~~~~
68
+ 1 import type { AuthSession } from '@sqrzro/server/auth';
69
+    ~~~~~~~~~~~~~~~~~~~~~
70
70
 
71
- [2:01:13 PM] Found 10 errors. Watching for file changes.
71
+ 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.
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/proxy';`
72
73
 
73
- [2:01:16 PM] File change detected. Starting incremental compilation...
74
+ 2 import type { ProxyRedirect } from '@sqrzro/server/proxy';
75
+    ~~~~~~~~~~~~~~~~~~~~~~
74
76
 
75
- [2:01:16 PM] Found 0 errors. Watching for file changes.
77
+ [2:49:11 PM] Found 11 errors. Watching for file changes.
76
78
 
77
- [2:13:49 PM] File change detected. Starting incremental compilation...
79
+ [2:49:15 PM] File change detected. Starting incremental compilation...
78
80
 
79
- [2:13:50 PM] Found 0 errors. Watching for file changes.
81
+ [2:49:15 PM] Found 0 errors. Watching for file changes.
80
82
 
81
- [2:13:50 PM] File change detected. Starting incremental compilation...
83
+ [2:49:47 PM] File change detected. Starting incremental compilation...
82
84
 
83
- [2:13:50 PM] Found 0 errors. Watching for file changes.
85
+ [2:49:47 PM] Found 0 errors. Watching for file changes.
84
86
 
85
- [2:21:47 PM] File change detected. Starting incremental compilation...
87
+ [2:49:52 PM] File change detected. Starting incremental compilation...
86
88
 
87
- [2:21:47 PM] Found 0 errors. Watching for file changes.
89
+ [2:49:52 PM] Found 0 errors. Watching for file changes.
88
90
 
89
- [2:21:49 PM] File change detected. Starting incremental compilation...
91
+ [2:50:44 PM] File change detected. Starting incremental compilation...
90
92
 
91
- [2:21:49 PM] Found 0 errors. Watching for file changes.
93
+ [2:50:44 PM] Found 0 errors. Watching for file changes.
94
+
95
+ [2:50:48 PM] File change detected. Starting incremental compilation...
96
+
97
+ [2:50:48 PM] Found 0 errors. Watching for file changes.
98
+
99
+ [2:59:21 PM] File change detected. Starting incremental compilation...
100
+
101
+ [2:59:21 PM] Found 0 errors. Watching for file changes.
102
+
103
+ [2:59:25 PM] File change detected. Starting incremental compilation...
104
+
105
+ [2:59:25 PM] Found 0 errors. Watching for file changes.
106
+
107
+ [2:59:51 PM] File change detected. Starting incremental compilation...
108
+
109
+ [2:59:51 PM] Found 0 errors. Watching for file changes.
110
+
111
+ [3:00:13 PM] File change detected. Starting incremental compilation...
112
+
113
+ [3:00:13 PM] Found 0 errors. Watching for file changes.
114
+
115
+ [3:00:21 PM] File change detected. Starting incremental compilation...
116
+
117
+ [3:00:21 PM] Found 0 errors. Watching for file changes.
118
+
119
+ [3:04:21 PM] File change detected. Starting incremental compilation...
120
+
121
+ [3:04:21 PM] Found 0 errors. Watching for file changes.
92
122
 
93
123
   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;
@@ -10,7 +10,7 @@ const schema = z
10
10
  })
11
11
  .required({ password: true, token: true });
12
12
  async function fn(data) {
13
- await updatePasswordWithToken(data.token, data.password);
13
+ await updatePasswordWithToken('PASSWORD', data.token, data.password);
14
14
  return redirect('/auth/login');
15
15
  }
16
16
  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;
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@sqrzro/auth",
3
3
  "type": "module",
4
- "version": "4.0.0-alpha.7",
4
+ "version": "4.0.0-alpha.8",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "dependencies": {
8
8
  "zod": "^4.3.6",
9
- "@sqrzro/server": "^4.0.0-alpha.16",
9
+ "@sqrzro/server": "^4.0.0-alpha.18",
10
10
  "@sqrzro/ui": "^4.0.0-alpha.13"
11
11
  },
12
12
  "devDependencies": {
@@ -8,7 +8,7 @@ import type { AuthClassNameProps } from '../../interfaces';
8
8
 
9
9
  import Password from '../Password';
10
10
 
11
- interface AuthPageProps extends AuthClassNameProps, NextPageProps {
11
+ export interface AuthProps extends AuthClassNameProps, NextPageProps {
12
12
  logo?: React.ReactElement;
13
13
  }
14
14
 
@@ -16,7 +16,7 @@ async function AuthComponent({
16
16
  classNames,
17
17
  params,
18
18
  searchParams,
19
- }: AuthPageProps): Promise<React.ReactElement> {
19
+ }: AuthProps): Promise<React.ReactElement> {
20
20
  const awaitedParams = await params;
21
21
 
22
22
  if (!awaitedParams || !Array.isArray(awaitedParams.auth) || awaitedParams.auth.length !== 1) {
@@ -38,7 +38,7 @@ async function AuthComponent({
38
38
  return notFound();
39
39
  }
40
40
 
41
- function Auth({ classNames, logo, ...props }: AuthPageProps): React.ReactElement {
41
+ function Auth({ classNames, logo, ...props }: AuthProps): React.ReactElement {
42
42
  return (
43
43
  <div className={classNames?.root}>
44
44
  <div className={classNames?.logo}>{logo}</div>
@@ -15,7 +15,7 @@ const schema = z
15
15
  .required({ password: true, token: true });
16
16
 
17
17
  async function fn(data: PasswordResetFormFields): Promise<void> {
18
- await updatePasswordWithToken(data.token, data.password);
18
+ await updatePasswordWithToken('PASSWORD', data.token, data.password);
19
19
  return redirect('/auth/login');
20
20
  }
21
21
 
@@ -0,0 +1,34 @@
1
+ import type { AuthSession } from '@sqrzro/server/auth';
2
+ import type { ProxyRedirect } from '@sqrzro/server/proxy';
3
+ import type { NextRequest } from 'next/server';
4
+
5
+ import type { AuthConfigObject } from './interfaces';
6
+
7
+ async function handleAuthProxy(
8
+ session: AuthSession | null,
9
+ request: NextRequest,
10
+ config?: AuthConfigObject
11
+ ): Promise<ProxyRedirect | null> {
12
+ const pathname = request.nextUrl.pathname;
13
+
14
+ if (session) {
15
+ if (pathname.startsWith('/auth')) {
16
+ return { redirect: '/' };
17
+ }
18
+ return null;
19
+ }
20
+
21
+ if (pathname.startsWith('/auth') || config?.allow?.includes(pathname)) {
22
+ return null;
23
+ }
24
+
25
+ return { redirect: '/auth/login' };
26
+ }
27
+
28
+ function getAuthProxy(
29
+ config?: AuthConfigObject
30
+ ): (session: AuthSession | null, request: NextRequest) => Promise<ProxyRedirect | null> {
31
+ return (session, request) => handleAuthProxy(session, request, config);
32
+ }
33
+
34
+ export default getAuthProxy;
package/src/index.ts CHANGED
@@ -1,4 +1,8 @@
1
+ export type { AuthClassNames, AuthConfigObject } from './interfaces';
2
+
3
+ export type { AuthProps } from './components/Auth';
1
4
  export { default as Auth } from './components/Auth';
5
+
2
6
  export { default as LogoutButton } from './components/LogoutButton';
3
7
 
4
- export { default as handleProxy } from './handle-proxy';
8
+ export { default as getAuthProxy } from './get-auth-proxy';
package/src/interfaces.ts CHANGED
@@ -1,3 +1,7 @@
1
+ export interface AuthConfigObject {
2
+ allow?: string[];
3
+ }
4
+
1
5
  export interface AuthClassNames {
2
6
  actions: string;
3
7
  footer: string;
@@ -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;