@hono/auth-js 1.0.6 → 1.0.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.
- package/README.md +3 -2
- package/dist/index.d.mts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +29 -24
- package/dist/index.mjs +28 -24
- package/dist/react.d.mts +0 -39
- package/dist/react.d.ts +0 -39
- package/dist/react.js +10 -13
- package/dist/react.mjs +10 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -22,8 +22,9 @@ AUTH_URL=#optional
|
|
|
22
22
|
## How to Use
|
|
23
23
|
|
|
24
24
|
```ts
|
|
25
|
-
import { Hono,Context } from 'hono'
|
|
26
|
-
import { authHandler, initAuthConfig, verifyAuth, AuthConfig } from "@hono/auth-js"
|
|
25
|
+
import { Hono, Context } from 'hono'
|
|
26
|
+
import { authHandler, initAuthConfig, verifyAuth, type AuthConfig } from "@hono/auth-js"
|
|
27
|
+
import GitHub from "@auth/core/providers/github"
|
|
27
28
|
|
|
28
29
|
const app = new Hono()
|
|
29
30
|
|
package/dist/index.d.mts
CHANGED
|
@@ -11,6 +11,7 @@ declare module 'hono' {
|
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
type AuthEnv = {
|
|
14
|
+
AUTH_URL?: string;
|
|
14
15
|
AUTH_SECRET: string;
|
|
15
16
|
AUTH_REDIRECT_PROXY_URL?: string;
|
|
16
17
|
[key: string]: string | undefined;
|
|
@@ -23,10 +24,11 @@ type AuthUser = {
|
|
|
23
24
|
interface AuthConfig extends Omit<AuthConfig$1, 'raw'> {
|
|
24
25
|
}
|
|
25
26
|
type ConfigHandler = (c: Context) => AuthConfig;
|
|
27
|
+
declare function setEnvDefaults(env: AuthEnv, config: AuthConfig): void;
|
|
26
28
|
declare function reqWithEnvUrl(req: Request, authUrl?: string): Request;
|
|
27
29
|
declare function getAuthUser(c: Context): Promise<AuthUser | null>;
|
|
28
30
|
declare function verifyAuth(): MiddlewareHandler;
|
|
29
31
|
declare function initAuthConfig(cb: ConfigHandler): MiddlewareHandler;
|
|
30
32
|
declare function authHandler(): MiddlewareHandler;
|
|
31
33
|
|
|
32
|
-
export { type AuthConfig, type AuthEnv, type AuthUser, type ConfigHandler, authHandler, getAuthUser, initAuthConfig, reqWithEnvUrl, verifyAuth };
|
|
34
|
+
export { type AuthConfig, type AuthEnv, type AuthUser, type ConfigHandler, authHandler, getAuthUser, initAuthConfig, reqWithEnvUrl, setEnvDefaults, verifyAuth };
|
package/dist/index.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ declare module 'hono' {
|
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
type AuthEnv = {
|
|
14
|
+
AUTH_URL?: string;
|
|
14
15
|
AUTH_SECRET: string;
|
|
15
16
|
AUTH_REDIRECT_PROXY_URL?: string;
|
|
16
17
|
[key: string]: string | undefined;
|
|
@@ -23,10 +24,11 @@ type AuthUser = {
|
|
|
23
24
|
interface AuthConfig extends Omit<AuthConfig$1, 'raw'> {
|
|
24
25
|
}
|
|
25
26
|
type ConfigHandler = (c: Context) => AuthConfig;
|
|
27
|
+
declare function setEnvDefaults(env: AuthEnv, config: AuthConfig): void;
|
|
26
28
|
declare function reqWithEnvUrl(req: Request, authUrl?: string): Request;
|
|
27
29
|
declare function getAuthUser(c: Context): Promise<AuthUser | null>;
|
|
28
30
|
declare function verifyAuth(): MiddlewareHandler;
|
|
29
31
|
declare function initAuthConfig(cb: ConfigHandler): MiddlewareHandler;
|
|
30
32
|
declare function authHandler(): MiddlewareHandler;
|
|
31
33
|
|
|
32
|
-
export { type AuthConfig, type AuthEnv, type AuthUser, type ConfigHandler, authHandler, getAuthUser, initAuthConfig, reqWithEnvUrl, verifyAuth };
|
|
34
|
+
export { type AuthConfig, type AuthEnv, type AuthUser, type ConfigHandler, authHandler, getAuthUser, initAuthConfig, reqWithEnvUrl, setEnvDefaults, verifyAuth };
|
package/dist/index.js
CHANGED
|
@@ -24,12 +24,19 @@ __export(src_exports, {
|
|
|
24
24
|
getAuthUser: () => getAuthUser,
|
|
25
25
|
initAuthConfig: () => initAuthConfig,
|
|
26
26
|
reqWithEnvUrl: () => reqWithEnvUrl,
|
|
27
|
+
setEnvDefaults: () => setEnvDefaults,
|
|
27
28
|
verifyAuth: () => verifyAuth
|
|
28
29
|
});
|
|
29
30
|
module.exports = __toCommonJS(src_exports);
|
|
30
31
|
var import_core = require("@auth/core");
|
|
31
32
|
var import_adapter = require("hono/adapter");
|
|
32
33
|
var import_http_exception = require("hono/http-exception");
|
|
34
|
+
var import_core2 = require("@auth/core");
|
|
35
|
+
function setEnvDefaults(env2, config) {
|
|
36
|
+
config.secret ??= env2.AUTH_SECRET;
|
|
37
|
+
config.basePath ||= "/api/auth";
|
|
38
|
+
(0, import_core2.setEnvDefaults)(env2, config);
|
|
39
|
+
}
|
|
33
40
|
function reqWithEnvUrl(req, authUrl) {
|
|
34
41
|
if (authUrl) {
|
|
35
42
|
const reqUrlObj = new URL(req.url);
|
|
@@ -38,31 +45,27 @@ function reqWithEnvUrl(req, authUrl) {
|
|
|
38
45
|
props.forEach((prop) => reqUrlObj[prop] = authUrlObj[prop]);
|
|
39
46
|
return new Request(reqUrlObj.href, req);
|
|
40
47
|
} else {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
finalProvider.clientId ??= env2[`AUTH_${ID}_ID`];
|
|
54
|
-
finalProvider.clientSecret ??= env2[`AUTH_${ID}_SECRET`];
|
|
55
|
-
if (finalProvider.type === "oidc") {
|
|
56
|
-
finalProvider.issuer ??= env2[`AUTH_${ID}_ISSUER`];
|
|
57
|
-
}
|
|
48
|
+
const url = new URL(req.url);
|
|
49
|
+
const proto = req.headers.get("x-forwarded-proto");
|
|
50
|
+
const host = req.headers.get("x-forwarded-host") ?? req.headers.get("host");
|
|
51
|
+
if (proto != null)
|
|
52
|
+
url.protocol = proto.endsWith(":") ? proto : proto + ":";
|
|
53
|
+
if (host) {
|
|
54
|
+
url.host = host;
|
|
55
|
+
const portMatch = host.match(/:(\d+)$/);
|
|
56
|
+
if (portMatch)
|
|
57
|
+
url.port = portMatch[1];
|
|
58
|
+
else
|
|
59
|
+
url.port = "";
|
|
58
60
|
}
|
|
59
|
-
return
|
|
60
|
-
}
|
|
61
|
+
return new Request(url.href, req);
|
|
62
|
+
}
|
|
61
63
|
}
|
|
62
64
|
async function getAuthUser(c) {
|
|
63
65
|
const config = c.get("authConfig");
|
|
64
|
-
|
|
65
|
-
|
|
66
|
+
let ctxEnv = (0, import_adapter.env)(c);
|
|
67
|
+
setEnvDefaults(ctxEnv, config);
|
|
68
|
+
const origin = new URL(reqWithEnvUrl(c.req.raw, ctxEnv.AUTH_URL).url).origin;
|
|
66
69
|
const request = new Request(`${origin}${config.basePath}/session`, {
|
|
67
70
|
headers: { cookie: c.req.header("cookie") ?? "" }
|
|
68
71
|
});
|
|
@@ -107,11 +110,12 @@ function initAuthConfig(cb) {
|
|
|
107
110
|
function authHandler() {
|
|
108
111
|
return async (c) => {
|
|
109
112
|
const config = c.get("authConfig");
|
|
110
|
-
|
|
111
|
-
|
|
113
|
+
let ctxEnv = (0, import_adapter.env)(c);
|
|
114
|
+
setEnvDefaults(ctxEnv, config);
|
|
115
|
+
if (!config.secret || config.secret.length === 0) {
|
|
112
116
|
throw new import_http_exception.HTTPException(500, { message: "Missing AUTH_SECRET" });
|
|
113
117
|
}
|
|
114
|
-
const res = await (0, import_core.Auth)(reqWithEnvUrl(c.req.raw,
|
|
118
|
+
const res = await (0, import_core.Auth)(reqWithEnvUrl(c.req.raw, ctxEnv.AUTH_URL), config);
|
|
115
119
|
return new Response(res.body, res);
|
|
116
120
|
};
|
|
117
121
|
}
|
|
@@ -121,5 +125,6 @@ function authHandler() {
|
|
|
121
125
|
getAuthUser,
|
|
122
126
|
initAuthConfig,
|
|
123
127
|
reqWithEnvUrl,
|
|
128
|
+
setEnvDefaults,
|
|
124
129
|
verifyAuth
|
|
125
130
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
import { Auth } from "@auth/core";
|
|
3
3
|
import { env } from "hono/adapter";
|
|
4
4
|
import { HTTPException } from "hono/http-exception";
|
|
5
|
+
import { setEnvDefaults as coreSetEnvDefaults } from "@auth/core";
|
|
6
|
+
function setEnvDefaults(env2, config) {
|
|
7
|
+
config.secret ??= env2.AUTH_SECRET;
|
|
8
|
+
config.basePath ||= "/api/auth";
|
|
9
|
+
coreSetEnvDefaults(env2, config);
|
|
10
|
+
}
|
|
5
11
|
function reqWithEnvUrl(req, authUrl) {
|
|
6
12
|
if (authUrl) {
|
|
7
13
|
const reqUrlObj = new URL(req.url);
|
|
@@ -10,31 +16,27 @@ function reqWithEnvUrl(req, authUrl) {
|
|
|
10
16
|
props.forEach((prop) => reqUrlObj[prop] = authUrlObj[prop]);
|
|
11
17
|
return new Request(reqUrlObj.href, req);
|
|
12
18
|
} else {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
finalProvider.clientId ??= env2[`AUTH_${ID}_ID`];
|
|
26
|
-
finalProvider.clientSecret ??= env2[`AUTH_${ID}_SECRET`];
|
|
27
|
-
if (finalProvider.type === "oidc") {
|
|
28
|
-
finalProvider.issuer ??= env2[`AUTH_${ID}_ISSUER`];
|
|
29
|
-
}
|
|
19
|
+
const url = new URL(req.url);
|
|
20
|
+
const proto = req.headers.get("x-forwarded-proto");
|
|
21
|
+
const host = req.headers.get("x-forwarded-host") ?? req.headers.get("host");
|
|
22
|
+
if (proto != null)
|
|
23
|
+
url.protocol = proto.endsWith(":") ? proto : proto + ":";
|
|
24
|
+
if (host) {
|
|
25
|
+
url.host = host;
|
|
26
|
+
const portMatch = host.match(/:(\d+)$/);
|
|
27
|
+
if (portMatch)
|
|
28
|
+
url.port = portMatch[1];
|
|
29
|
+
else
|
|
30
|
+
url.port = "";
|
|
30
31
|
}
|
|
31
|
-
return
|
|
32
|
-
}
|
|
32
|
+
return new Request(url.href, req);
|
|
33
|
+
}
|
|
33
34
|
}
|
|
34
35
|
async function getAuthUser(c) {
|
|
35
36
|
const config = c.get("authConfig");
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
let ctxEnv = env(c);
|
|
38
|
+
setEnvDefaults(ctxEnv, config);
|
|
39
|
+
const origin = new URL(reqWithEnvUrl(c.req.raw, ctxEnv.AUTH_URL).url).origin;
|
|
38
40
|
const request = new Request(`${origin}${config.basePath}/session`, {
|
|
39
41
|
headers: { cookie: c.req.header("cookie") ?? "" }
|
|
40
42
|
});
|
|
@@ -79,11 +81,12 @@ function initAuthConfig(cb) {
|
|
|
79
81
|
function authHandler() {
|
|
80
82
|
return async (c) => {
|
|
81
83
|
const config = c.get("authConfig");
|
|
82
|
-
|
|
83
|
-
|
|
84
|
+
let ctxEnv = env(c);
|
|
85
|
+
setEnvDefaults(ctxEnv, config);
|
|
86
|
+
if (!config.secret || config.secret.length === 0) {
|
|
84
87
|
throw new HTTPException(500, { message: "Missing AUTH_SECRET" });
|
|
85
88
|
}
|
|
86
|
-
const res = await Auth(reqWithEnvUrl(c.req.raw,
|
|
89
|
+
const res = await Auth(reqWithEnvUrl(c.req.raw, ctxEnv.AUTH_URL), config);
|
|
87
90
|
return new Response(res.body, res);
|
|
88
91
|
};
|
|
89
92
|
}
|
|
@@ -92,5 +95,6 @@ export {
|
|
|
92
95
|
getAuthUser,
|
|
93
96
|
initAuthConfig,
|
|
94
97
|
reqWithEnvUrl,
|
|
98
|
+
setEnvDefaults,
|
|
95
99
|
verifyAuth
|
|
96
100
|
};
|
package/dist/react.d.mts
CHANGED
|
@@ -6,19 +6,12 @@ interface AuthClientConfig {
|
|
|
6
6
|
baseUrl: string;
|
|
7
7
|
basePath: string;
|
|
8
8
|
credentials?: RequestCredentials;
|
|
9
|
-
/** Stores last session response */
|
|
10
9
|
_session?: Session | null | undefined;
|
|
11
|
-
/** Used for timestamp since last sycned (in seconds) */
|
|
12
10
|
_lastSync: number;
|
|
13
|
-
/**
|
|
14
|
-
* Stores the `SessionProvider`'s session update method to be able to
|
|
15
|
-
* trigger session updates from places like `signIn` or `signOut`
|
|
16
|
-
*/
|
|
17
11
|
_getSession: (...args: any[]) => any;
|
|
18
12
|
}
|
|
19
13
|
interface UseSessionOptions<R extends boolean> {
|
|
20
14
|
required: R;
|
|
21
|
-
/** Defaults to `signIn` */
|
|
22
15
|
onUnauthenticated?: () => void;
|
|
23
16
|
}
|
|
24
17
|
type LiteralUnion<T extends U, U = string> = T | (U & Record<never, never>);
|
|
@@ -45,12 +38,7 @@ interface SignInResponse {
|
|
|
45
38
|
ok: boolean;
|
|
46
39
|
url: string | null;
|
|
47
40
|
}
|
|
48
|
-
/**
|
|
49
|
-
* Match `inputType` of `new URLSearchParams(inputType)`
|
|
50
|
-
* @internal
|
|
51
|
-
*/
|
|
52
41
|
type SignInAuthorizationParams = string | string[][] | Record<string, string> | URLSearchParams;
|
|
53
|
-
/** [Documentation](https://next-auth.js.org/getting-started/client#using-the-redirect-false-option-1) */
|
|
54
42
|
interface SignOutResponse {
|
|
55
43
|
url: string;
|
|
56
44
|
}
|
|
@@ -60,32 +48,13 @@ interface SignOutParams<R extends boolean = true> {
|
|
|
60
48
|
/** [Documentation](https://next-auth.js.org/getting-started/client#using-the-redirect-false-option-1 */
|
|
61
49
|
redirect?: R;
|
|
62
50
|
}
|
|
63
|
-
/**
|
|
64
|
-
|
|
65
|
-
* If you have session expiry times of 30 days (the default) or more, then you probably don't need to change any of the default options.
|
|
66
|
-
*
|
|
67
|
-
* However, if you need to customize the session behavior and/or are using short session expiry times, you can pass options to the provider to customize the behavior of the {@link useSession} hook.
|
|
68
|
-
*/
|
|
69
51
|
interface SessionProviderProps {
|
|
70
52
|
children: React.ReactNode;
|
|
71
53
|
session?: Session | null;
|
|
72
54
|
baseUrl?: string;
|
|
73
55
|
basePath?: string;
|
|
74
|
-
/**
|
|
75
|
-
* A time interval (in seconds) after which the session will be re-fetched.
|
|
76
|
-
* If set to `0` (default), the session is not polled.
|
|
77
|
-
*/
|
|
78
56
|
refetchInterval?: number;
|
|
79
|
-
/**
|
|
80
|
-
* `SessionProvider` automatically refetches the session when the user switches between windows.
|
|
81
|
-
* This option activates this behaviour if set to `true` (default).
|
|
82
|
-
*/
|
|
83
57
|
refetchOnWindowFocus?: boolean;
|
|
84
|
-
/**
|
|
85
|
-
* Set to `false` to stop polling when the device has no internet access offline (determined by `navigator.onLine`)
|
|
86
|
-
*
|
|
87
|
-
* [`navigator.onLine` documentation](https://developer.mozilla.org/en-US/docs/Web/API/NavigatorOnLine/onLine)
|
|
88
|
-
*/
|
|
89
58
|
refetchWhenOffline?: false;
|
|
90
59
|
}
|
|
91
60
|
|
|
@@ -97,7 +66,6 @@ declare class AuthConfigManager {
|
|
|
97
66
|
getConfig(): AuthClientConfig;
|
|
98
67
|
}
|
|
99
68
|
declare const authConfigManager: AuthConfigManager;
|
|
100
|
-
/** @todo Document */
|
|
101
69
|
type UpdateSession = (data?: any) => Promise<Session | null>;
|
|
102
70
|
type SessionContextValue<R extends boolean = false> = R extends true ? {
|
|
103
71
|
update: UpdateSession;
|
|
@@ -132,13 +100,6 @@ interface GetSessionParams {
|
|
|
132
100
|
broadcast?: boolean;
|
|
133
101
|
}
|
|
134
102
|
declare function getSession(params?: GetSessionParams): Promise<Session | null>;
|
|
135
|
-
/**
|
|
136
|
-
* Returns the current Cross-Site Request Forgery Token (CSRF Token)
|
|
137
|
-
* required to make requests that changes state. (e.g. signing in or out, or updating the session).
|
|
138
|
-
*
|
|
139
|
-
* [CSRF Prevention: Double Submit Cookie](https://cheatsheetseries.owasp.org/cheatsheets/Cross-Site_Request_Forgery_Prevention_Cheat_Sheet.html#double-submit-cookie)
|
|
140
|
-
* @internal
|
|
141
|
-
*/
|
|
142
103
|
declare function getCsrfToken(): Promise<string>;
|
|
143
104
|
type ProvidersType = Record<LiteralUnion<BuiltInProviderType>, ClientSafeProvider>;
|
|
144
105
|
declare function getProviders(): Promise<ProvidersType | null>;
|
package/dist/react.d.ts
CHANGED
|
@@ -6,19 +6,12 @@ interface AuthClientConfig {
|
|
|
6
6
|
baseUrl: string;
|
|
7
7
|
basePath: string;
|
|
8
8
|
credentials?: RequestCredentials;
|
|
9
|
-
/** Stores last session response */
|
|
10
9
|
_session?: Session | null | undefined;
|
|
11
|
-
/** Used for timestamp since last sycned (in seconds) */
|
|
12
10
|
_lastSync: number;
|
|
13
|
-
/**
|
|
14
|
-
* Stores the `SessionProvider`'s session update method to be able to
|
|
15
|
-
* trigger session updates from places like `signIn` or `signOut`
|
|
16
|
-
*/
|
|
17
11
|
_getSession: (...args: any[]) => any;
|
|
18
12
|
}
|
|
19
13
|
interface UseSessionOptions<R extends boolean> {
|
|
20
14
|
required: R;
|
|
21
|
-
/** Defaults to `signIn` */
|
|
22
15
|
onUnauthenticated?: () => void;
|
|
23
16
|
}
|
|
24
17
|
type LiteralUnion<T extends U, U = string> = T | (U & Record<never, never>);
|
|
@@ -45,12 +38,7 @@ interface SignInResponse {
|
|
|
45
38
|
ok: boolean;
|
|
46
39
|
url: string | null;
|
|
47
40
|
}
|
|
48
|
-
/**
|
|
49
|
-
* Match `inputType` of `new URLSearchParams(inputType)`
|
|
50
|
-
* @internal
|
|
51
|
-
*/
|
|
52
41
|
type SignInAuthorizationParams = string | string[][] | Record<string, string> | URLSearchParams;
|
|
53
|
-
/** [Documentation](https://next-auth.js.org/getting-started/client#using-the-redirect-false-option-1) */
|
|
54
42
|
interface SignOutResponse {
|
|
55
43
|
url: string;
|
|
56
44
|
}
|
|
@@ -60,32 +48,13 @@ interface SignOutParams<R extends boolean = true> {
|
|
|
60
48
|
/** [Documentation](https://next-auth.js.org/getting-started/client#using-the-redirect-false-option-1 */
|
|
61
49
|
redirect?: R;
|
|
62
50
|
}
|
|
63
|
-
/**
|
|
64
|
-
|
|
65
|
-
* If you have session expiry times of 30 days (the default) or more, then you probably don't need to change any of the default options.
|
|
66
|
-
*
|
|
67
|
-
* However, if you need to customize the session behavior and/or are using short session expiry times, you can pass options to the provider to customize the behavior of the {@link useSession} hook.
|
|
68
|
-
*/
|
|
69
51
|
interface SessionProviderProps {
|
|
70
52
|
children: React.ReactNode;
|
|
71
53
|
session?: Session | null;
|
|
72
54
|
baseUrl?: string;
|
|
73
55
|
basePath?: string;
|
|
74
|
-
/**
|
|
75
|
-
* A time interval (in seconds) after which the session will be re-fetched.
|
|
76
|
-
* If set to `0` (default), the session is not polled.
|
|
77
|
-
*/
|
|
78
56
|
refetchInterval?: number;
|
|
79
|
-
/**
|
|
80
|
-
* `SessionProvider` automatically refetches the session when the user switches between windows.
|
|
81
|
-
* This option activates this behaviour if set to `true` (default).
|
|
82
|
-
*/
|
|
83
57
|
refetchOnWindowFocus?: boolean;
|
|
84
|
-
/**
|
|
85
|
-
* Set to `false` to stop polling when the device has no internet access offline (determined by `navigator.onLine`)
|
|
86
|
-
*
|
|
87
|
-
* [`navigator.onLine` documentation](https://developer.mozilla.org/en-US/docs/Web/API/NavigatorOnLine/onLine)
|
|
88
|
-
*/
|
|
89
58
|
refetchWhenOffline?: false;
|
|
90
59
|
}
|
|
91
60
|
|
|
@@ -97,7 +66,6 @@ declare class AuthConfigManager {
|
|
|
97
66
|
getConfig(): AuthClientConfig;
|
|
98
67
|
}
|
|
99
68
|
declare const authConfigManager: AuthConfigManager;
|
|
100
|
-
/** @todo Document */
|
|
101
69
|
type UpdateSession = (data?: any) => Promise<Session | null>;
|
|
102
70
|
type SessionContextValue<R extends boolean = false> = R extends true ? {
|
|
103
71
|
update: UpdateSession;
|
|
@@ -132,13 +100,6 @@ interface GetSessionParams {
|
|
|
132
100
|
broadcast?: boolean;
|
|
133
101
|
}
|
|
134
102
|
declare function getSession(params?: GetSessionParams): Promise<Session | null>;
|
|
135
|
-
/**
|
|
136
|
-
* Returns the current Cross-Site Request Forgery Token (CSRF Token)
|
|
137
|
-
* required to make requests that changes state. (e.g. signing in or out, or updating the session).
|
|
138
|
-
*
|
|
139
|
-
* [CSRF Prevention: Double Submit Cookie](https://cheatsheetseries.owasp.org/cheatsheets/Cross-Site_Request_Forgery_Prevention_Cheat_Sheet.html#double-submit-cookie)
|
|
140
|
-
* @internal
|
|
141
|
-
*/
|
|
142
103
|
declare function getCsrfToken(): Promise<string>;
|
|
143
104
|
type ProvidersType = Record<LiteralUnion<BuiltInProviderType>, ClientSafeProvider>;
|
|
144
105
|
declare function getProviders(): Promise<ProvidersType | null>;
|
package/dist/react.js
CHANGED
|
@@ -79,9 +79,9 @@ function useOnline() {
|
|
|
79
79
|
const [isOnline, setIsOnline] = React.useState(
|
|
80
80
|
typeof navigator !== "undefined" ? navigator.onLine : false
|
|
81
81
|
);
|
|
82
|
-
const setOnline = () => setIsOnline(true);
|
|
83
|
-
const setOffline = () => setIsOnline(false);
|
|
84
82
|
React.useEffect(() => {
|
|
83
|
+
const setOnline = () => setIsOnline(true);
|
|
84
|
+
const setOffline = () => setIsOnline(false);
|
|
85
85
|
window.addEventListener("online", setOnline);
|
|
86
86
|
window.addEventListener("offline", setOffline);
|
|
87
87
|
return () => {
|
|
@@ -95,16 +95,13 @@ function now() {
|
|
|
95
95
|
return Math.floor(Date.now() / 1e3);
|
|
96
96
|
}
|
|
97
97
|
function parseUrl(url) {
|
|
98
|
-
const defaultUrl =
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
const _url = new URL(url ?? defaultUrl);
|
|
103
|
-
const path = (_url.pathname === "/" ? defaultUrl.pathname : _url.pathname).replace(/\/$/, "");
|
|
104
|
-
const base = `${_url.origin}${path}`;
|
|
98
|
+
const defaultUrl = "http://localhost:3000/api/auth";
|
|
99
|
+
const parsedUrl = new URL(url?.startsWith("http") ? url : `https://${url}` || defaultUrl);
|
|
100
|
+
const path = parsedUrl.pathname === "/" ? "/api/auth" : parsedUrl.pathname.replace(/\/$/, "");
|
|
101
|
+
const base = `${parsedUrl.origin}${path}`;
|
|
105
102
|
return {
|
|
106
|
-
origin:
|
|
107
|
-
host:
|
|
103
|
+
origin: parsedUrl.origin,
|
|
104
|
+
host: parsedUrl.host,
|
|
108
105
|
path,
|
|
109
106
|
base,
|
|
110
107
|
toString: () => base
|
|
@@ -115,8 +112,8 @@ function parseUrl(url) {
|
|
|
115
112
|
var AuthConfigManager = class _AuthConfigManager {
|
|
116
113
|
static instance = null;
|
|
117
114
|
_config = {
|
|
118
|
-
baseUrl: parseUrl(window.location.origin).origin,
|
|
119
|
-
basePath: parseUrl(window.location.origin).path,
|
|
115
|
+
baseUrl: typeof window !== "undefined" ? parseUrl(window.location.origin).origin : "",
|
|
116
|
+
basePath: typeof window !== "undefined" ? parseUrl(window.location.origin).path : "/api/auth",
|
|
120
117
|
credentials: "same-origin",
|
|
121
118
|
_lastSync: 0,
|
|
122
119
|
_session: void 0,
|
package/dist/react.mjs
CHANGED
|
@@ -37,9 +37,9 @@ function useOnline() {
|
|
|
37
37
|
const [isOnline, setIsOnline] = React.useState(
|
|
38
38
|
typeof navigator !== "undefined" ? navigator.onLine : false
|
|
39
39
|
);
|
|
40
|
-
const setOnline = () => setIsOnline(true);
|
|
41
|
-
const setOffline = () => setIsOnline(false);
|
|
42
40
|
React.useEffect(() => {
|
|
41
|
+
const setOnline = () => setIsOnline(true);
|
|
42
|
+
const setOffline = () => setIsOnline(false);
|
|
43
43
|
window.addEventListener("online", setOnline);
|
|
44
44
|
window.addEventListener("offline", setOffline);
|
|
45
45
|
return () => {
|
|
@@ -53,16 +53,13 @@ function now() {
|
|
|
53
53
|
return Math.floor(Date.now() / 1e3);
|
|
54
54
|
}
|
|
55
55
|
function parseUrl(url) {
|
|
56
|
-
const defaultUrl =
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
const _url = new URL(url ?? defaultUrl);
|
|
61
|
-
const path = (_url.pathname === "/" ? defaultUrl.pathname : _url.pathname).replace(/\/$/, "");
|
|
62
|
-
const base = `${_url.origin}${path}`;
|
|
56
|
+
const defaultUrl = "http://localhost:3000/api/auth";
|
|
57
|
+
const parsedUrl = new URL(url?.startsWith("http") ? url : `https://${url}` || defaultUrl);
|
|
58
|
+
const path = parsedUrl.pathname === "/" ? "/api/auth" : parsedUrl.pathname.replace(/\/$/, "");
|
|
59
|
+
const base = `${parsedUrl.origin}${path}`;
|
|
63
60
|
return {
|
|
64
|
-
origin:
|
|
65
|
-
host:
|
|
61
|
+
origin: parsedUrl.origin,
|
|
62
|
+
host: parsedUrl.host,
|
|
66
63
|
path,
|
|
67
64
|
base,
|
|
68
65
|
toString: () => base
|
|
@@ -73,8 +70,8 @@ function parseUrl(url) {
|
|
|
73
70
|
var AuthConfigManager = class _AuthConfigManager {
|
|
74
71
|
static instance = null;
|
|
75
72
|
_config = {
|
|
76
|
-
baseUrl: parseUrl(window.location.origin).origin,
|
|
77
|
-
basePath: parseUrl(window.location.origin).path,
|
|
73
|
+
baseUrl: typeof window !== "undefined" ? parseUrl(window.location.origin).origin : "",
|
|
74
|
+
basePath: typeof window !== "undefined" ? parseUrl(window.location.origin).path : "/api/auth",
|
|
78
75
|
credentials: "same-origin",
|
|
79
76
|
_lastSync: 0,
|
|
80
77
|
_session: void 0,
|