@hono/auth-js 1.0.10 → 1.0.12
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/README.md +41 -65
- package/dist/index.js +24 -27
- package/dist/index.mjs +24 -27
- package/dist/react.d.mts +27 -39
- package/dist/react.d.ts +27 -39
- package/dist/react.js +187 -198
- package/dist/react.mjs +187 -198
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -16,78 +16,72 @@ Before starting using the middleware you must set the following environment vari
|
|
|
16
16
|
|
|
17
17
|
```plain
|
|
18
18
|
AUTH_SECRET=#required
|
|
19
|
-
AUTH_URL
|
|
19
|
+
AUTH_URL=https://example.com/api/auth
|
|
20
20
|
```
|
|
21
21
|
|
|
22
22
|
## How to Use
|
|
23
23
|
|
|
24
24
|
```ts
|
|
25
|
-
import { Hono
|
|
26
|
-
import { authHandler, initAuthConfig, verifyAuth
|
|
27
|
-
import GitHub from
|
|
25
|
+
import { Hono } from 'hono'
|
|
26
|
+
import { authHandler, initAuthConfig, verifyAuth } from '@hono/auth-js'
|
|
27
|
+
import GitHub from '@auth/core/providers/github'
|
|
28
28
|
|
|
29
29
|
const app = new Hono()
|
|
30
30
|
|
|
31
|
-
app.use(
|
|
31
|
+
app.use(
|
|
32
|
+
'*',
|
|
33
|
+
initAuthConfig((c) => ({
|
|
34
|
+
secret: c.env.AUTH_SECRET,
|
|
35
|
+
providers: [
|
|
36
|
+
GitHub({
|
|
37
|
+
clientId: c.env.GITHUB_ID,
|
|
38
|
+
clientSecret: c.env.GITHUB_SECRET,
|
|
39
|
+
}),
|
|
40
|
+
],
|
|
41
|
+
}))
|
|
42
|
+
)
|
|
32
43
|
|
|
33
|
-
app.use(
|
|
44
|
+
app.use('/api/auth/*', authHandler())
|
|
34
45
|
|
|
35
46
|
app.use('/api/*', verifyAuth())
|
|
36
47
|
|
|
37
48
|
app.get('/api/protected', (c) => {
|
|
38
|
-
const auth = c.get(
|
|
49
|
+
const auth = c.get('authUser')
|
|
39
50
|
return c.json(auth)
|
|
40
51
|
})
|
|
41
52
|
|
|
42
|
-
function getAuthConfig(c: Context): AuthConfig {
|
|
43
|
-
return {
|
|
44
|
-
secret: c.env.AUTH_SECRET,
|
|
45
|
-
providers: [
|
|
46
|
-
GitHub({
|
|
47
|
-
clientId: c.env.GITHUB_ID,
|
|
48
|
-
clientSecret: c.env.GITHUB_SECRET
|
|
49
|
-
}),
|
|
50
|
-
]
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
53
|
export default app
|
|
55
54
|
```
|
|
56
55
|
|
|
57
56
|
React component
|
|
58
|
-
```tsx
|
|
59
|
-
import { SessionProvider } from "@hono/auth-js/react"
|
|
60
57
|
|
|
61
|
-
|
|
58
|
+
```tsx
|
|
59
|
+
import { SessionProvider, useSession } from '@hono/auth-js/react'
|
|
62
60
|
|
|
61
|
+
export default function App() {
|
|
63
62
|
return (
|
|
64
63
|
<SessionProvider>
|
|
65
|
-
|
|
64
|
+
<Children />
|
|
66
65
|
</SessionProvider>
|
|
67
66
|
)
|
|
68
67
|
}
|
|
69
68
|
|
|
70
69
|
function Children() {
|
|
71
70
|
const { data: session, status } = useSession()
|
|
72
|
-
return
|
|
73
|
-
<div >
|
|
74
|
-
I am {session?.user}
|
|
75
|
-
</div>
|
|
76
|
-
)
|
|
71
|
+
return <div>I am {session?.user}</div>
|
|
77
72
|
}
|
|
78
73
|
```
|
|
74
|
+
|
|
79
75
|
Default `/api/auth` path can be changed to something else but that will also require you to change path in react app.
|
|
80
76
|
|
|
81
77
|
```tsx
|
|
82
|
-
import {SessionProvider,authConfigManager,useSession } from
|
|
78
|
+
import { SessionProvider, authConfigManager, useSession } from '@hono/auth-js/react'
|
|
83
79
|
|
|
84
80
|
authConfigManager.setConfig({
|
|
85
|
-
baseUrl: '', //needed for cross domain setup.
|
|
86
81
|
basePath: '/custom', // if auth route is diff from /api/auth
|
|
87
|
-
|
|
88
|
-
});
|
|
82
|
+
})
|
|
89
83
|
|
|
90
|
-
export default
|
|
84
|
+
export default function App() {
|
|
91
85
|
return (
|
|
92
86
|
<SessionProvider>
|
|
93
87
|
<Children />
|
|
@@ -97,45 +91,27 @@ export default function App() {
|
|
|
97
91
|
|
|
98
92
|
function Children() {
|
|
99
93
|
const { data: session, status } = useSession()
|
|
100
|
-
return
|
|
101
|
-
<div >
|
|
102
|
-
I am {session?.user}
|
|
103
|
-
</div>
|
|
104
|
-
)
|
|
94
|
+
return <div>I am {session?.user}</div>
|
|
105
95
|
}
|
|
106
96
|
```
|
|
107
|
-
For cross domain setup as mentioned above you need to set these cors headers in hono along with change in same site cookie attribute.[Read More Here](https://next-auth.js.org/configuration/options#cookies)
|
|
108
|
-
``` ts
|
|
109
|
-
app.use(
|
|
110
|
-
"*",
|
|
111
|
-
cors({
|
|
112
|
-
origin: (origin) => origin,
|
|
113
|
-
allowHeaders: ["Content-Type"],
|
|
114
|
-
credentials: true,
|
|
115
|
-
})
|
|
116
|
-
)
|
|
117
|
-
```
|
|
118
97
|
|
|
119
|
-
|
|
120
|
-
SessionProvider is not needed with react query.This wrapper is enough
|
|
98
|
+
SessionProvider is not needed with react query.Use useQuery hook to fetch session data.
|
|
121
99
|
|
|
122
100
|
```ts
|
|
123
|
-
const useSession = ()=>{
|
|
124
|
-
const { data
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
})
|
|
134
|
-
|
|
101
|
+
const useSession = () => {
|
|
102
|
+
const { data, status } = useQuery({
|
|
103
|
+
queryKey: ['session'],
|
|
104
|
+
queryFn: async () => {
|
|
105
|
+
const res = await fetch('/api/auth/session')
|
|
106
|
+
return res.json()
|
|
107
|
+
},
|
|
108
|
+
staleTime: 5 * (60 * 1000),
|
|
109
|
+
gcTime: 10 * (60 * 1000),
|
|
110
|
+
refetchOnWindowFocus: true,
|
|
111
|
+
})
|
|
112
|
+
return { session: data, status }
|
|
135
113
|
}
|
|
136
114
|
```
|
|
137
|
-
> [!WARNING]
|
|
138
|
-
> You can't use event updates which SessionProvider provides and session will not be in sync across tabs if you use react query wrapper but in RQ5 you can enable this using Broadcast channel (see RQ docs).
|
|
139
115
|
|
|
140
116
|
Working example repo https://github.com/divyam234/next-auth-hono-react
|
|
141
117
|
|
package/dist/index.js
CHANGED
|
@@ -34,7 +34,6 @@ var import_http_exception = require("hono/http-exception");
|
|
|
34
34
|
var import_core2 = require("@auth/core");
|
|
35
35
|
function setEnvDefaults(env2, config) {
|
|
36
36
|
config.secret ??= env2.AUTH_SECRET;
|
|
37
|
-
config.basePath ||= "/api/auth";
|
|
38
37
|
(0, import_core2.setEnvDefaults)(env2, config);
|
|
39
38
|
}
|
|
40
39
|
async function cloneRequest(input, request, headers) {
|
|
@@ -43,13 +42,10 @@ async function cloneRequest(input, request, headers) {
|
|
|
43
42
|
method: request.method,
|
|
44
43
|
headers: headers ?? new Headers(request.headers),
|
|
45
44
|
body: request.method === "GET" || request.method === "HEAD" ? void 0 : await request.blob(),
|
|
46
|
-
// @ts-ignore: TS2353
|
|
47
45
|
referrer: "referrer" in request ? request.referrer : void 0,
|
|
48
|
-
// deno-lint-ignore no-explicit-any
|
|
49
46
|
referrerPolicy: request.referrerPolicy,
|
|
50
47
|
mode: request.mode,
|
|
51
48
|
credentials: request.credentials,
|
|
52
|
-
// @ts-ignore: TS2353
|
|
53
49
|
cache: request.cache,
|
|
54
50
|
redirect: request.redirect,
|
|
55
51
|
integrity: request.integrity,
|
|
@@ -64,28 +60,30 @@ async function reqWithEnvUrl(req, authUrl) {
|
|
|
64
60
|
const reqUrlObj = new URL(req.url);
|
|
65
61
|
const authUrlObj = new URL(authUrl);
|
|
66
62
|
const props = ["hostname", "protocol", "port", "password", "username"];
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const url = new URL(req.url);
|
|
71
|
-
const headers = new Headers(req.headers);
|
|
72
|
-
const proto = headers.get("x-forwarded-proto");
|
|
73
|
-
const host = headers.get("x-forwarded-host") ?? headers.get("host");
|
|
74
|
-
if (proto != null)
|
|
75
|
-
url.protocol = proto.endsWith(":") ? proto : proto + ":";
|
|
76
|
-
if (host != null) {
|
|
77
|
-
url.host = host;
|
|
78
|
-
const portMatch = host.match(/:(\d+)$/);
|
|
79
|
-
if (portMatch)
|
|
80
|
-
url.port = portMatch[1];
|
|
81
|
-
else
|
|
82
|
-
url.port = "";
|
|
83
|
-
headers.delete("x-forwarded-host");
|
|
84
|
-
headers.delete("Host");
|
|
85
|
-
headers.set("Host", host);
|
|
63
|
+
for (const prop of props) {
|
|
64
|
+
if (authUrlObj[prop])
|
|
65
|
+
reqUrlObj[prop] = authUrlObj[prop];
|
|
86
66
|
}
|
|
87
|
-
return cloneRequest(
|
|
67
|
+
return cloneRequest(reqUrlObj.href, req);
|
|
68
|
+
}
|
|
69
|
+
const url = new URL(req.url);
|
|
70
|
+
const headers = new Headers(req.headers);
|
|
71
|
+
const proto = headers.get("x-forwarded-proto");
|
|
72
|
+
const host = headers.get("x-forwarded-host") ?? headers.get("host");
|
|
73
|
+
if (proto != null)
|
|
74
|
+
url.protocol = proto.endsWith(":") ? proto : `${proto}:`;
|
|
75
|
+
if (host != null) {
|
|
76
|
+
url.host = host;
|
|
77
|
+
const portMatch = host.match(/:(\d+)$/);
|
|
78
|
+
if (portMatch)
|
|
79
|
+
url.port = portMatch[1];
|
|
80
|
+
else
|
|
81
|
+
url.port = "";
|
|
82
|
+
headers.delete("x-forwarded-host");
|
|
83
|
+
headers.delete("Host");
|
|
84
|
+
headers.set("Host", host);
|
|
88
85
|
}
|
|
86
|
+
return cloneRequest(url.href, req, headers);
|
|
89
87
|
}
|
|
90
88
|
async function getAuthUser(c) {
|
|
91
89
|
const config = c.get("authConfig");
|
|
@@ -110,7 +108,7 @@ async function getAuthUser(c) {
|
|
|
110
108
|
}
|
|
111
109
|
});
|
|
112
110
|
const session = await response.json();
|
|
113
|
-
return session
|
|
111
|
+
return session?.user ? authUser : null;
|
|
114
112
|
}
|
|
115
113
|
function verifyAuth() {
|
|
116
114
|
return async (c, next) => {
|
|
@@ -121,9 +119,8 @@ function verifyAuth() {
|
|
|
121
119
|
status: 401
|
|
122
120
|
});
|
|
123
121
|
throw new import_http_exception.HTTPException(401, { res });
|
|
124
|
-
} else {
|
|
125
|
-
c.set("authUser", authUser);
|
|
126
122
|
}
|
|
123
|
+
c.set("authUser", authUser);
|
|
127
124
|
await next();
|
|
128
125
|
};
|
|
129
126
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -5,7 +5,6 @@ import { HTTPException } from "hono/http-exception";
|
|
|
5
5
|
import { setEnvDefaults as coreSetEnvDefaults } from "@auth/core";
|
|
6
6
|
function setEnvDefaults(env2, config) {
|
|
7
7
|
config.secret ??= env2.AUTH_SECRET;
|
|
8
|
-
config.basePath ||= "/api/auth";
|
|
9
8
|
coreSetEnvDefaults(env2, config);
|
|
10
9
|
}
|
|
11
10
|
async function cloneRequest(input, request, headers) {
|
|
@@ -14,13 +13,10 @@ async function cloneRequest(input, request, headers) {
|
|
|
14
13
|
method: request.method,
|
|
15
14
|
headers: headers ?? new Headers(request.headers),
|
|
16
15
|
body: request.method === "GET" || request.method === "HEAD" ? void 0 : await request.blob(),
|
|
17
|
-
// @ts-ignore: TS2353
|
|
18
16
|
referrer: "referrer" in request ? request.referrer : void 0,
|
|
19
|
-
// deno-lint-ignore no-explicit-any
|
|
20
17
|
referrerPolicy: request.referrerPolicy,
|
|
21
18
|
mode: request.mode,
|
|
22
19
|
credentials: request.credentials,
|
|
23
|
-
// @ts-ignore: TS2353
|
|
24
20
|
cache: request.cache,
|
|
25
21
|
redirect: request.redirect,
|
|
26
22
|
integrity: request.integrity,
|
|
@@ -35,28 +31,30 @@ async function reqWithEnvUrl(req, authUrl) {
|
|
|
35
31
|
const reqUrlObj = new URL(req.url);
|
|
36
32
|
const authUrlObj = new URL(authUrl);
|
|
37
33
|
const props = ["hostname", "protocol", "port", "password", "username"];
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const url = new URL(req.url);
|
|
42
|
-
const headers = new Headers(req.headers);
|
|
43
|
-
const proto = headers.get("x-forwarded-proto");
|
|
44
|
-
const host = headers.get("x-forwarded-host") ?? headers.get("host");
|
|
45
|
-
if (proto != null)
|
|
46
|
-
url.protocol = proto.endsWith(":") ? proto : proto + ":";
|
|
47
|
-
if (host != null) {
|
|
48
|
-
url.host = host;
|
|
49
|
-
const portMatch = host.match(/:(\d+)$/);
|
|
50
|
-
if (portMatch)
|
|
51
|
-
url.port = portMatch[1];
|
|
52
|
-
else
|
|
53
|
-
url.port = "";
|
|
54
|
-
headers.delete("x-forwarded-host");
|
|
55
|
-
headers.delete("Host");
|
|
56
|
-
headers.set("Host", host);
|
|
34
|
+
for (const prop of props) {
|
|
35
|
+
if (authUrlObj[prop])
|
|
36
|
+
reqUrlObj[prop] = authUrlObj[prop];
|
|
57
37
|
}
|
|
58
|
-
return cloneRequest(
|
|
38
|
+
return cloneRequest(reqUrlObj.href, req);
|
|
39
|
+
}
|
|
40
|
+
const url = new URL(req.url);
|
|
41
|
+
const headers = new Headers(req.headers);
|
|
42
|
+
const proto = headers.get("x-forwarded-proto");
|
|
43
|
+
const host = headers.get("x-forwarded-host") ?? headers.get("host");
|
|
44
|
+
if (proto != null)
|
|
45
|
+
url.protocol = proto.endsWith(":") ? proto : `${proto}:`;
|
|
46
|
+
if (host != null) {
|
|
47
|
+
url.host = host;
|
|
48
|
+
const portMatch = host.match(/:(\d+)$/);
|
|
49
|
+
if (portMatch)
|
|
50
|
+
url.port = portMatch[1];
|
|
51
|
+
else
|
|
52
|
+
url.port = "";
|
|
53
|
+
headers.delete("x-forwarded-host");
|
|
54
|
+
headers.delete("Host");
|
|
55
|
+
headers.set("Host", host);
|
|
59
56
|
}
|
|
57
|
+
return cloneRequest(url.href, req, headers);
|
|
60
58
|
}
|
|
61
59
|
async function getAuthUser(c) {
|
|
62
60
|
const config = c.get("authConfig");
|
|
@@ -81,7 +79,7 @@ async function getAuthUser(c) {
|
|
|
81
79
|
}
|
|
82
80
|
});
|
|
83
81
|
const session = await response.json();
|
|
84
|
-
return session
|
|
82
|
+
return session?.user ? authUser : null;
|
|
85
83
|
}
|
|
86
84
|
function verifyAuth() {
|
|
87
85
|
return async (c, next) => {
|
|
@@ -92,9 +90,8 @@ function verifyAuth() {
|
|
|
92
90
|
status: 401
|
|
93
91
|
});
|
|
94
92
|
throw new HTTPException(401, { res });
|
|
95
|
-
} else {
|
|
96
|
-
c.set("authUser", authUser);
|
|
97
93
|
}
|
|
94
|
+
c.set("authUser", authUser);
|
|
98
95
|
await next();
|
|
99
96
|
};
|
|
100
97
|
}
|
package/dist/react.d.mts
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import { BuiltInProviderType, ProviderType, RedirectableProviderType } from '@auth/core/providers';
|
|
2
2
|
import { Session } from '@auth/core/types';
|
|
3
|
-
import * as React from 'react';
|
|
3
|
+
import * as React$1 from 'react';
|
|
4
4
|
|
|
5
|
+
interface GetSessionParams {
|
|
6
|
+
event?: 'storage' | 'timer' | 'hidden' | string;
|
|
7
|
+
triggerEvent?: boolean;
|
|
8
|
+
}
|
|
5
9
|
interface AuthClientConfig {
|
|
6
10
|
baseUrl: string;
|
|
7
11
|
basePath: string;
|
|
8
|
-
credentials
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
+
credentials: RequestCredentials;
|
|
13
|
+
lastSync: number;
|
|
14
|
+
session: Session | null;
|
|
15
|
+
fetchSession: (params?: GetSessionParams) => Promise<void>;
|
|
12
16
|
}
|
|
13
17
|
interface UseSessionOptions<R extends boolean> {
|
|
14
18
|
required: R;
|
|
@@ -23,13 +27,7 @@ interface ClientSafeProvider {
|
|
|
23
27
|
callbackUrl: string;
|
|
24
28
|
}
|
|
25
29
|
interface SignInOptions extends Record<string, unknown> {
|
|
26
|
-
/**
|
|
27
|
-
* Specify to which URL the user will be redirected after signing in. Defaults to the page URL the sign-in is initiated from.
|
|
28
|
-
*
|
|
29
|
-
* [Documentation](https://next-auth.js.org/getting-started/client#specifying-a-callbackurl)
|
|
30
|
-
*/
|
|
31
30
|
callbackUrl?: string;
|
|
32
|
-
/** [Documentation](https://next-auth.js.org/getting-started/client#using-the-redirect-false-option) */
|
|
33
31
|
redirect?: boolean;
|
|
34
32
|
}
|
|
35
33
|
interface SignInResponse {
|
|
@@ -43,29 +41,16 @@ interface SignOutResponse {
|
|
|
43
41
|
url: string;
|
|
44
42
|
}
|
|
45
43
|
interface SignOutParams<R extends boolean = true> {
|
|
46
|
-
/** [Documentation](https://next-auth.js.org/getting-started/client#specifying-a-callbackurl-1) */
|
|
47
44
|
callbackUrl?: string;
|
|
48
|
-
/** [Documentation](https://next-auth.js.org/getting-started/client#using-the-redirect-false-option-1 */
|
|
49
45
|
redirect?: R;
|
|
50
46
|
}
|
|
51
47
|
interface SessionProviderProps {
|
|
52
48
|
children: React.ReactNode;
|
|
53
49
|
session?: Session | null;
|
|
54
|
-
baseUrl?: string;
|
|
55
|
-
basePath?: string;
|
|
56
50
|
refetchInterval?: number;
|
|
57
51
|
refetchOnWindowFocus?: boolean;
|
|
58
52
|
refetchWhenOffline?: false;
|
|
59
53
|
}
|
|
60
|
-
|
|
61
|
-
declare class AuthConfigManager {
|
|
62
|
-
private static instance;
|
|
63
|
-
_config: AuthClientConfig;
|
|
64
|
-
static getInstance(): AuthConfigManager;
|
|
65
|
-
setConfig(userConfig: Partial<AuthClientConfig>): void;
|
|
66
|
-
getConfig(): AuthClientConfig;
|
|
67
|
-
}
|
|
68
|
-
declare const authConfigManager: AuthConfigManager;
|
|
69
54
|
type UpdateSession = (data?: any) => Promise<Session | null>;
|
|
70
55
|
type SessionContextValue<R extends boolean = false> = R extends true ? {
|
|
71
56
|
update: UpdateSession;
|
|
@@ -84,31 +69,34 @@ type SessionContextValue<R extends boolean = false> = R extends true ? {
|
|
|
84
69
|
data: null;
|
|
85
70
|
status: 'unauthenticated' | 'loading';
|
|
86
71
|
};
|
|
87
|
-
|
|
72
|
+
|
|
73
|
+
declare class AuthConfigManager {
|
|
74
|
+
private static instance;
|
|
75
|
+
private config;
|
|
76
|
+
private constructor();
|
|
77
|
+
private createDefaultConfig;
|
|
78
|
+
static getInstance(): AuthConfigManager;
|
|
79
|
+
setConfig(userConfig: Partial<AuthClientConfig>): void;
|
|
80
|
+
getConfig(): AuthClientConfig;
|
|
81
|
+
initializeConfig(hasInitialSession: boolean): void;
|
|
82
|
+
}
|
|
83
|
+
declare const authConfigManager: AuthConfigManager;
|
|
84
|
+
declare const SessionContext: React$1.Context<{
|
|
88
85
|
update: UpdateSession;
|
|
89
86
|
data: Session;
|
|
90
|
-
status:
|
|
87
|
+
status: "authenticated";
|
|
91
88
|
} | {
|
|
92
89
|
update: UpdateSession;
|
|
93
90
|
data: null;
|
|
94
|
-
status:
|
|
91
|
+
status: "loading" | "unauthenticated";
|
|
95
92
|
} | undefined>;
|
|
96
|
-
declare function useSession<R extends boolean>(options?: UseSessionOptions<R>): SessionContextValue<R>;
|
|
97
|
-
interface GetSessionParams {
|
|
98
|
-
event?: 'storage' | 'timer' | 'hidden' | string;
|
|
99
|
-
triggerEvent?: boolean;
|
|
100
|
-
broadcast?: boolean;
|
|
101
|
-
}
|
|
102
93
|
declare function getSession(params?: GetSessionParams): Promise<Session | null>;
|
|
103
94
|
declare function getCsrfToken(): Promise<string>;
|
|
95
|
+
declare function SessionProvider(props: SessionProviderProps): React$1.JSX.Element;
|
|
96
|
+
declare function useSession<R extends boolean>(options?: UseSessionOptions<R>): SessionContextValue<R>;
|
|
104
97
|
type ProvidersType = Record<LiteralUnion<BuiltInProviderType>, ClientSafeProvider>;
|
|
105
98
|
declare function getProviders(): Promise<ProvidersType | null>;
|
|
106
99
|
declare function signIn<P extends RedirectableProviderType | undefined = undefined>(provider?: LiteralUnion<P extends RedirectableProviderType ? P | BuiltInProviderType : BuiltInProviderType>, options?: SignInOptions, authorizationParams?: SignInAuthorizationParams): Promise<P extends RedirectableProviderType ? SignInResponse | undefined : undefined>;
|
|
107
|
-
/**
|
|
108
|
-
* Initiate a signout, by destroying the current session.
|
|
109
|
-
* Handles CSRF protection.
|
|
110
|
-
*/
|
|
111
100
|
declare function signOut<R extends boolean = true>(options?: SignOutParams<R>): Promise<R extends true ? undefined : SignOutResponse>;
|
|
112
|
-
declare function SessionProvider(props: SessionProviderProps): React.JSX.Element;
|
|
113
101
|
|
|
114
|
-
export {
|
|
102
|
+
export { SessionContext, SessionProvider, authConfigManager, getCsrfToken, getProviders, getSession, signIn, signOut, useSession };
|
package/dist/react.d.ts
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import { BuiltInProviderType, ProviderType, RedirectableProviderType } from '@auth/core/providers';
|
|
2
2
|
import { Session } from '@auth/core/types';
|
|
3
|
-
import * as React from 'react';
|
|
3
|
+
import * as React$1 from 'react';
|
|
4
4
|
|
|
5
|
+
interface GetSessionParams {
|
|
6
|
+
event?: 'storage' | 'timer' | 'hidden' | string;
|
|
7
|
+
triggerEvent?: boolean;
|
|
8
|
+
}
|
|
5
9
|
interface AuthClientConfig {
|
|
6
10
|
baseUrl: string;
|
|
7
11
|
basePath: string;
|
|
8
|
-
credentials
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
+
credentials: RequestCredentials;
|
|
13
|
+
lastSync: number;
|
|
14
|
+
session: Session | null;
|
|
15
|
+
fetchSession: (params?: GetSessionParams) => Promise<void>;
|
|
12
16
|
}
|
|
13
17
|
interface UseSessionOptions<R extends boolean> {
|
|
14
18
|
required: R;
|
|
@@ -23,13 +27,7 @@ interface ClientSafeProvider {
|
|
|
23
27
|
callbackUrl: string;
|
|
24
28
|
}
|
|
25
29
|
interface SignInOptions extends Record<string, unknown> {
|
|
26
|
-
/**
|
|
27
|
-
* Specify to which URL the user will be redirected after signing in. Defaults to the page URL the sign-in is initiated from.
|
|
28
|
-
*
|
|
29
|
-
* [Documentation](https://next-auth.js.org/getting-started/client#specifying-a-callbackurl)
|
|
30
|
-
*/
|
|
31
30
|
callbackUrl?: string;
|
|
32
|
-
/** [Documentation](https://next-auth.js.org/getting-started/client#using-the-redirect-false-option) */
|
|
33
31
|
redirect?: boolean;
|
|
34
32
|
}
|
|
35
33
|
interface SignInResponse {
|
|
@@ -43,29 +41,16 @@ interface SignOutResponse {
|
|
|
43
41
|
url: string;
|
|
44
42
|
}
|
|
45
43
|
interface SignOutParams<R extends boolean = true> {
|
|
46
|
-
/** [Documentation](https://next-auth.js.org/getting-started/client#specifying-a-callbackurl-1) */
|
|
47
44
|
callbackUrl?: string;
|
|
48
|
-
/** [Documentation](https://next-auth.js.org/getting-started/client#using-the-redirect-false-option-1 */
|
|
49
45
|
redirect?: R;
|
|
50
46
|
}
|
|
51
47
|
interface SessionProviderProps {
|
|
52
48
|
children: React.ReactNode;
|
|
53
49
|
session?: Session | null;
|
|
54
|
-
baseUrl?: string;
|
|
55
|
-
basePath?: string;
|
|
56
50
|
refetchInterval?: number;
|
|
57
51
|
refetchOnWindowFocus?: boolean;
|
|
58
52
|
refetchWhenOffline?: false;
|
|
59
53
|
}
|
|
60
|
-
|
|
61
|
-
declare class AuthConfigManager {
|
|
62
|
-
private static instance;
|
|
63
|
-
_config: AuthClientConfig;
|
|
64
|
-
static getInstance(): AuthConfigManager;
|
|
65
|
-
setConfig(userConfig: Partial<AuthClientConfig>): void;
|
|
66
|
-
getConfig(): AuthClientConfig;
|
|
67
|
-
}
|
|
68
|
-
declare const authConfigManager: AuthConfigManager;
|
|
69
54
|
type UpdateSession = (data?: any) => Promise<Session | null>;
|
|
70
55
|
type SessionContextValue<R extends boolean = false> = R extends true ? {
|
|
71
56
|
update: UpdateSession;
|
|
@@ -84,31 +69,34 @@ type SessionContextValue<R extends boolean = false> = R extends true ? {
|
|
|
84
69
|
data: null;
|
|
85
70
|
status: 'unauthenticated' | 'loading';
|
|
86
71
|
};
|
|
87
|
-
|
|
72
|
+
|
|
73
|
+
declare class AuthConfigManager {
|
|
74
|
+
private static instance;
|
|
75
|
+
private config;
|
|
76
|
+
private constructor();
|
|
77
|
+
private createDefaultConfig;
|
|
78
|
+
static getInstance(): AuthConfigManager;
|
|
79
|
+
setConfig(userConfig: Partial<AuthClientConfig>): void;
|
|
80
|
+
getConfig(): AuthClientConfig;
|
|
81
|
+
initializeConfig(hasInitialSession: boolean): void;
|
|
82
|
+
}
|
|
83
|
+
declare const authConfigManager: AuthConfigManager;
|
|
84
|
+
declare const SessionContext: React$1.Context<{
|
|
88
85
|
update: UpdateSession;
|
|
89
86
|
data: Session;
|
|
90
|
-
status:
|
|
87
|
+
status: "authenticated";
|
|
91
88
|
} | {
|
|
92
89
|
update: UpdateSession;
|
|
93
90
|
data: null;
|
|
94
|
-
status:
|
|
91
|
+
status: "loading" | "unauthenticated";
|
|
95
92
|
} | undefined>;
|
|
96
|
-
declare function useSession<R extends boolean>(options?: UseSessionOptions<R>): SessionContextValue<R>;
|
|
97
|
-
interface GetSessionParams {
|
|
98
|
-
event?: 'storage' | 'timer' | 'hidden' | string;
|
|
99
|
-
triggerEvent?: boolean;
|
|
100
|
-
broadcast?: boolean;
|
|
101
|
-
}
|
|
102
93
|
declare function getSession(params?: GetSessionParams): Promise<Session | null>;
|
|
103
94
|
declare function getCsrfToken(): Promise<string>;
|
|
95
|
+
declare function SessionProvider(props: SessionProviderProps): React$1.JSX.Element;
|
|
96
|
+
declare function useSession<R extends boolean>(options?: UseSessionOptions<R>): SessionContextValue<R>;
|
|
104
97
|
type ProvidersType = Record<LiteralUnion<BuiltInProviderType>, ClientSafeProvider>;
|
|
105
98
|
declare function getProviders(): Promise<ProvidersType | null>;
|
|
106
99
|
declare function signIn<P extends RedirectableProviderType | undefined = undefined>(provider?: LiteralUnion<P extends RedirectableProviderType ? P | BuiltInProviderType : BuiltInProviderType>, options?: SignInOptions, authorizationParams?: SignInAuthorizationParams): Promise<P extends RedirectableProviderType ? SignInResponse | undefined : undefined>;
|
|
107
|
-
/**
|
|
108
|
-
* Initiate a signout, by destroying the current session.
|
|
109
|
-
* Handles CSRF protection.
|
|
110
|
-
*/
|
|
111
100
|
declare function signOut<R extends boolean = true>(options?: SignOutParams<R>): Promise<R extends true ? undefined : SignOutResponse>;
|
|
112
|
-
declare function SessionProvider(props: SessionProviderProps): React.JSX.Element;
|
|
113
101
|
|
|
114
|
-
export {
|
|
102
|
+
export { SessionContext, SessionProvider, authConfigManager, getCsrfToken, getProviders, getSession, signIn, signOut, useSession };
|