@hono/auth-js 1.0.7 → 1.0.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.
- package/README.md +3 -2
- package/dist/index.d.mts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +56 -26
- package/dist/index.mjs +56 -27
- package/dist/react.d.mts +0 -32
- package/dist/react.d.ts +0 -32
- package/dist/react.js +8 -11
- package/dist/react.mjs +8 -11
- 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
|
@@ -24,10 +24,11 @@ type AuthUser = {
|
|
|
24
24
|
interface AuthConfig extends Omit<AuthConfig$1, 'raw'> {
|
|
25
25
|
}
|
|
26
26
|
type ConfigHandler = (c: Context) => AuthConfig;
|
|
27
|
-
declare function
|
|
27
|
+
declare function setEnvDefaults(env: AuthEnv, config: AuthConfig): void;
|
|
28
|
+
declare function reqWithEnvUrl(req: Request, authUrl?: string): Promise<Request>;
|
|
28
29
|
declare function getAuthUser(c: Context): Promise<AuthUser | null>;
|
|
29
30
|
declare function verifyAuth(): MiddlewareHandler;
|
|
30
31
|
declare function initAuthConfig(cb: ConfigHandler): MiddlewareHandler;
|
|
31
32
|
declare function authHandler(): MiddlewareHandler;
|
|
32
33
|
|
|
33
|
-
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
|
@@ -24,10 +24,11 @@ type AuthUser = {
|
|
|
24
24
|
interface AuthConfig extends Omit<AuthConfig$1, 'raw'> {
|
|
25
25
|
}
|
|
26
26
|
type ConfigHandler = (c: Context) => AuthConfig;
|
|
27
|
-
declare function
|
|
27
|
+
declare function setEnvDefaults(env: AuthEnv, config: AuthConfig): void;
|
|
28
|
+
declare function reqWithEnvUrl(req: Request, authUrl?: string): Promise<Request>;
|
|
28
29
|
declare function getAuthUser(c: Context): Promise<AuthUser | null>;
|
|
29
30
|
declare function verifyAuth(): MiddlewareHandler;
|
|
30
31
|
declare function initAuthConfig(cb: ConfigHandler): MiddlewareHandler;
|
|
31
32
|
declare function authHandler(): MiddlewareHandler;
|
|
32
33
|
|
|
33
|
-
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,46 +24,74 @@ __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");
|
|
33
|
-
|
|
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
|
+
}
|
|
40
|
+
async function cloneRequest(input, request) {
|
|
41
|
+
if ((0, import_adapter.getRuntimeKey)() === "bun") {
|
|
42
|
+
return new Request(input, {
|
|
43
|
+
method: request.method,
|
|
44
|
+
headers: new Headers(request.headers),
|
|
45
|
+
body: request.method === "GET" || request.method === "HEAD" ? void 0 : await request.blob(),
|
|
46
|
+
// @ts-ignore: TS2353
|
|
47
|
+
referrer: "referrer" in request ? request.referrer : void 0,
|
|
48
|
+
// deno-lint-ignore no-explicit-any
|
|
49
|
+
referrerPolicy: request.referrerPolicy,
|
|
50
|
+
mode: request.mode,
|
|
51
|
+
credentials: request.credentials,
|
|
52
|
+
// @ts-ignore: TS2353
|
|
53
|
+
cache: request.cache,
|
|
54
|
+
redirect: request.redirect,
|
|
55
|
+
integrity: request.integrity,
|
|
56
|
+
keepalive: request.keepalive,
|
|
57
|
+
signal: request.signal
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
return new Request(input, request);
|
|
61
|
+
}
|
|
62
|
+
async function reqWithEnvUrl(req, authUrl) {
|
|
34
63
|
if (authUrl) {
|
|
35
64
|
const reqUrlObj = new URL(req.url);
|
|
36
65
|
const authUrlObj = new URL(authUrl);
|
|
37
66
|
const props = ["hostname", "protocol", "port", "password", "username"];
|
|
38
67
|
props.forEach((prop) => reqUrlObj[prop] = authUrlObj[prop]);
|
|
39
|
-
return
|
|
68
|
+
return cloneRequest(reqUrlObj.href, req);
|
|
40
69
|
} else {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
finalProvider.issuer ??= env2[`AUTH_${ID}_ISSUER`];
|
|
57
|
-
}
|
|
70
|
+
const url = new URL(req.url);
|
|
71
|
+
const proto = req.headers.get("x-forwarded-proto");
|
|
72
|
+
const host = req.headers.get("x-forwarded-host") ?? req.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
|
+
req.headers.delete("x-forwarded-host");
|
|
83
|
+
req.headers.delete("Host");
|
|
84
|
+
req.headers.set("Host", host);
|
|
58
85
|
}
|
|
59
|
-
return
|
|
60
|
-
}
|
|
86
|
+
return cloneRequest(url.href, req);
|
|
87
|
+
}
|
|
61
88
|
}
|
|
62
89
|
async function getAuthUser(c) {
|
|
63
90
|
const config = c.get("authConfig");
|
|
64
|
-
|
|
91
|
+
const ctxEnv = (0, import_adapter.env)(c);
|
|
65
92
|
setEnvDefaults(ctxEnv, config);
|
|
66
|
-
const
|
|
93
|
+
const authReq = await reqWithEnvUrl(c.req.raw, ctxEnv.AUTH_URL);
|
|
94
|
+
const origin = new URL(authReq.url).origin;
|
|
67
95
|
const request = new Request(`${origin}${config.basePath}/session`, {
|
|
68
96
|
headers: { cookie: c.req.header("cookie") ?? "" }
|
|
69
97
|
});
|
|
@@ -108,12 +136,13 @@ function initAuthConfig(cb) {
|
|
|
108
136
|
function authHandler() {
|
|
109
137
|
return async (c) => {
|
|
110
138
|
const config = c.get("authConfig");
|
|
111
|
-
|
|
139
|
+
const ctxEnv = (0, import_adapter.env)(c);
|
|
112
140
|
setEnvDefaults(ctxEnv, config);
|
|
113
|
-
if (!config.secret) {
|
|
141
|
+
if (!config.secret || config.secret.length === 0) {
|
|
114
142
|
throw new import_http_exception.HTTPException(500, { message: "Missing AUTH_SECRET" });
|
|
115
143
|
}
|
|
116
|
-
const
|
|
144
|
+
const authReq = await reqWithEnvUrl(c.req.raw, ctxEnv.AUTH_URL);
|
|
145
|
+
const res = await (0, import_core.Auth)(authReq, config);
|
|
117
146
|
return new Response(res.body, res);
|
|
118
147
|
};
|
|
119
148
|
}
|
|
@@ -123,5 +152,6 @@ function authHandler() {
|
|
|
123
152
|
getAuthUser,
|
|
124
153
|
initAuthConfig,
|
|
125
154
|
reqWithEnvUrl,
|
|
155
|
+
setEnvDefaults,
|
|
126
156
|
verifyAuth
|
|
127
157
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -1,41 +1,68 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
import { Auth } from "@auth/core";
|
|
3
|
-
import { env } from "hono/adapter";
|
|
3
|
+
import { env, getRuntimeKey } from "hono/adapter";
|
|
4
4
|
import { HTTPException } from "hono/http-exception";
|
|
5
|
-
|
|
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
|
+
}
|
|
11
|
+
async function cloneRequest(input, request) {
|
|
12
|
+
if (getRuntimeKey() === "bun") {
|
|
13
|
+
return new Request(input, {
|
|
14
|
+
method: request.method,
|
|
15
|
+
headers: new Headers(request.headers),
|
|
16
|
+
body: request.method === "GET" || request.method === "HEAD" ? void 0 : await request.blob(),
|
|
17
|
+
// @ts-ignore: TS2353
|
|
18
|
+
referrer: "referrer" in request ? request.referrer : void 0,
|
|
19
|
+
// deno-lint-ignore no-explicit-any
|
|
20
|
+
referrerPolicy: request.referrerPolicy,
|
|
21
|
+
mode: request.mode,
|
|
22
|
+
credentials: request.credentials,
|
|
23
|
+
// @ts-ignore: TS2353
|
|
24
|
+
cache: request.cache,
|
|
25
|
+
redirect: request.redirect,
|
|
26
|
+
integrity: request.integrity,
|
|
27
|
+
keepalive: request.keepalive,
|
|
28
|
+
signal: request.signal
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
return new Request(input, request);
|
|
32
|
+
}
|
|
33
|
+
async function reqWithEnvUrl(req, authUrl) {
|
|
6
34
|
if (authUrl) {
|
|
7
35
|
const reqUrlObj = new URL(req.url);
|
|
8
36
|
const authUrlObj = new URL(authUrl);
|
|
9
37
|
const props = ["hostname", "protocol", "port", "password", "username"];
|
|
10
38
|
props.forEach((prop) => reqUrlObj[prop] = authUrlObj[prop]);
|
|
11
|
-
return
|
|
39
|
+
return cloneRequest(reqUrlObj.href, req);
|
|
12
40
|
} else {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
finalProvider.issuer ??= env2[`AUTH_${ID}_ISSUER`];
|
|
29
|
-
}
|
|
41
|
+
const url = new URL(req.url);
|
|
42
|
+
const proto = req.headers.get("x-forwarded-proto");
|
|
43
|
+
const host = req.headers.get("x-forwarded-host") ?? req.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
|
+
req.headers.delete("x-forwarded-host");
|
|
54
|
+
req.headers.delete("Host");
|
|
55
|
+
req.headers.set("Host", host);
|
|
30
56
|
}
|
|
31
|
-
return
|
|
32
|
-
}
|
|
57
|
+
return cloneRequest(url.href, req);
|
|
58
|
+
}
|
|
33
59
|
}
|
|
34
60
|
async function getAuthUser(c) {
|
|
35
61
|
const config = c.get("authConfig");
|
|
36
|
-
|
|
62
|
+
const ctxEnv = env(c);
|
|
37
63
|
setEnvDefaults(ctxEnv, config);
|
|
38
|
-
const
|
|
64
|
+
const authReq = await reqWithEnvUrl(c.req.raw, ctxEnv.AUTH_URL);
|
|
65
|
+
const origin = new URL(authReq.url).origin;
|
|
39
66
|
const request = new Request(`${origin}${config.basePath}/session`, {
|
|
40
67
|
headers: { cookie: c.req.header("cookie") ?? "" }
|
|
41
68
|
});
|
|
@@ -80,12 +107,13 @@ function initAuthConfig(cb) {
|
|
|
80
107
|
function authHandler() {
|
|
81
108
|
return async (c) => {
|
|
82
109
|
const config = c.get("authConfig");
|
|
83
|
-
|
|
110
|
+
const ctxEnv = env(c);
|
|
84
111
|
setEnvDefaults(ctxEnv, config);
|
|
85
|
-
if (!config.secret) {
|
|
112
|
+
if (!config.secret || config.secret.length === 0) {
|
|
86
113
|
throw new HTTPException(500, { message: "Missing AUTH_SECRET" });
|
|
87
114
|
}
|
|
88
|
-
const
|
|
115
|
+
const authReq = await reqWithEnvUrl(c.req.raw, ctxEnv.AUTH_URL);
|
|
116
|
+
const res = await Auth(authReq, config);
|
|
89
117
|
return new Response(res.body, res);
|
|
90
118
|
};
|
|
91
119
|
}
|
|
@@ -94,5 +122,6 @@ export {
|
|
|
94
122
|
getAuthUser,
|
|
95
123
|
initAuthConfig,
|
|
96
124
|
reqWithEnvUrl,
|
|
125
|
+
setEnvDefaults,
|
|
97
126
|
verifyAuth
|
|
98
127
|
};
|
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;
|
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;
|
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
|
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
|