@hono/auth-js 1.0.16 → 1.1.0
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/CHANGELOG.md +12 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/react.cjs +12 -4
- package/dist/react.d.cts +8 -13
- package/dist/react.d.ts +8 -13
- package/dist/react.js +12 -4
- package/package.json +7 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @hono/auth-js
|
|
2
2
|
|
|
3
|
+
## 1.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#1324](https://github.com/honojs/middleware/pull/1324) [`d89fed7eecfa151c18b0a8cf95dae1dfe83dfec2`](https://github.com/honojs/middleware/commit/d89fed7eecfa151c18b0a8cf95dae1dfe83dfec2) Thanks [@jamestalmage](https://github.com/jamestalmage)! - Allow async authjs Config
|
|
8
|
+
|
|
9
|
+
## 1.0.17
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#1210](https://github.com/honojs/middleware/pull/1210) [`0758fd0af1f213131d0894299e5bec716d284580`](https://github.com/honojs/middleware/commit/0758fd0af1f213131d0894299e5bec716d284580) Thanks [@BarryThePenguin](https://github.com/BarryThePenguin)! - Add explicit return types
|
|
14
|
+
|
|
3
15
|
## 1.0.16
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
package/dist/index.d.cts
CHANGED
|
@@ -23,9 +23,9 @@ type AuthUser = {
|
|
|
23
23
|
};
|
|
24
24
|
interface AuthConfig extends Omit<AuthConfig$1, 'raw'> {
|
|
25
25
|
}
|
|
26
|
-
type ConfigHandler = (c: Context) => AuthConfig
|
|
26
|
+
type ConfigHandler = (c: Context) => AuthConfig | Promise<AuthConfig>;
|
|
27
27
|
declare function setEnvDefaults(env: AuthEnv, config: AuthConfig): void;
|
|
28
|
-
declare function reqWithEnvUrl(req: Request, authUrl?: string): Request
|
|
28
|
+
declare function reqWithEnvUrl(req: Request, authUrl?: string): Request;
|
|
29
29
|
declare function getAuthUser(c: Context): Promise<AuthUser | null>;
|
|
30
30
|
declare function verifyAuth(): MiddlewareHandler;
|
|
31
31
|
declare function initAuthConfig(cb: ConfigHandler): MiddlewareHandler;
|
package/dist/index.d.ts
CHANGED
|
@@ -23,9 +23,9 @@ type AuthUser = {
|
|
|
23
23
|
};
|
|
24
24
|
interface AuthConfig extends Omit<AuthConfig$1, 'raw'> {
|
|
25
25
|
}
|
|
26
|
-
type ConfigHandler = (c: Context) => AuthConfig
|
|
26
|
+
type ConfigHandler = (c: Context) => AuthConfig | Promise<AuthConfig>;
|
|
27
27
|
declare function setEnvDefaults(env: AuthEnv, config: AuthConfig): void;
|
|
28
|
-
declare function reqWithEnvUrl(req: Request, authUrl?: string): Request
|
|
28
|
+
declare function reqWithEnvUrl(req: Request, authUrl?: string): Request;
|
|
29
29
|
declare function getAuthUser(c: Context): Promise<AuthUser | null>;
|
|
30
30
|
declare function verifyAuth(): MiddlewareHandler;
|
|
31
31
|
declare function initAuthConfig(cb: ConfigHandler): MiddlewareHandler;
|
package/dist/index.js
CHANGED
package/dist/react.cjs
CHANGED
|
@@ -84,8 +84,12 @@ function useOnline() {
|
|
|
84
84
|
(0, import_react.useEffect)(() => {
|
|
85
85
|
const abortController = new AbortController();
|
|
86
86
|
const { signal } = abortController;
|
|
87
|
-
const setOnline = () =>
|
|
88
|
-
|
|
87
|
+
const setOnline = () => {
|
|
88
|
+
setIsOnline(true);
|
|
89
|
+
};
|
|
90
|
+
const setOffline = () => {
|
|
91
|
+
setIsOnline(false);
|
|
92
|
+
};
|
|
89
93
|
window.addEventListener("online", setOnline, { signal });
|
|
90
94
|
window.addEventListener("offline", setOffline, { signal });
|
|
91
95
|
return () => {
|
|
@@ -197,7 +201,9 @@ function useVisibilityChangeEventListener(authConfig, refetchOnWindowFocus) {
|
|
|
197
201
|
document.addEventListener("visibilitychange", handleVisibilityChange, {
|
|
198
202
|
signal: abortController.signal
|
|
199
203
|
});
|
|
200
|
-
return () =>
|
|
204
|
+
return () => {
|
|
205
|
+
abortController.abort();
|
|
206
|
+
};
|
|
201
207
|
}, [refetchOnWindowFocus]);
|
|
202
208
|
}
|
|
203
209
|
function useRefetchInterval(authConfig, refetchInterval, shouldRefetch) {
|
|
@@ -208,7 +214,9 @@ function useRefetchInterval(authConfig, refetchInterval, shouldRefetch) {
|
|
|
208
214
|
authConfig.fetchSession({ event: "poll" });
|
|
209
215
|
}
|
|
210
216
|
}, refetchInterval * 1e3);
|
|
211
|
-
return () =>
|
|
217
|
+
return () => {
|
|
218
|
+
clearInterval(intervalId);
|
|
219
|
+
};
|
|
212
220
|
}
|
|
213
221
|
}, [refetchInterval, shouldRefetch]);
|
|
214
222
|
}
|
package/dist/react.d.cts
CHANGED
|
@@ -75,6 +75,10 @@ type WindowProps = {
|
|
|
75
75
|
width: number;
|
|
76
76
|
height: number;
|
|
77
77
|
};
|
|
78
|
+
type AuthState = {
|
|
79
|
+
status: 'loading' | 'success' | 'errored';
|
|
80
|
+
error?: string;
|
|
81
|
+
};
|
|
78
82
|
|
|
79
83
|
declare class AuthConfigManager {
|
|
80
84
|
private static instance;
|
|
@@ -87,15 +91,7 @@ declare class AuthConfigManager {
|
|
|
87
91
|
initializeConfig(hasInitialSession: boolean): void;
|
|
88
92
|
}
|
|
89
93
|
declare const authConfigManager: AuthConfigManager;
|
|
90
|
-
declare const SessionContext: React$1.Context<
|
|
91
|
-
update: UpdateSession;
|
|
92
|
-
data: Session;
|
|
93
|
-
status: "authenticated";
|
|
94
|
-
} | {
|
|
95
|
-
update: UpdateSession;
|
|
96
|
-
data: null;
|
|
97
|
-
status: "unauthenticated" | "loading";
|
|
98
|
-
} | undefined>;
|
|
94
|
+
declare const SessionContext: React$1.Context<SessionContextValue | undefined>;
|
|
99
95
|
declare function getSession(params?: GetSessionParams): Promise<Session | null>;
|
|
100
96
|
declare function getCsrfToken(): Promise<string>;
|
|
101
97
|
declare function SessionProvider(props: SessionProviderProps): React$1.JSX.Element;
|
|
@@ -108,10 +104,9 @@ interface PopupLoginOptions extends Partial<Omit<WindowProps, 'url'>> {
|
|
|
108
104
|
onSuccess?: () => void;
|
|
109
105
|
callbackUrl?: string;
|
|
110
106
|
}
|
|
111
|
-
|
|
112
|
-
status: "loading" | "success" | "errored";
|
|
113
|
-
error?: string;
|
|
107
|
+
interface LoginState extends AuthState {
|
|
114
108
|
popUpSignin: () => Promise<void>;
|
|
115
|
-
}
|
|
109
|
+
}
|
|
110
|
+
declare const useOauthPopupLogin: (provider: Parameters<typeof signIn>[0], options?: PopupLoginOptions) => LoginState;
|
|
116
111
|
|
|
117
112
|
export { SessionContext, SessionProvider, authConfigManager, getCsrfToken, getProviders, getSession, signIn, signOut, useOauthPopupLogin, useSession };
|
package/dist/react.d.ts
CHANGED
|
@@ -75,6 +75,10 @@ type WindowProps = {
|
|
|
75
75
|
width: number;
|
|
76
76
|
height: number;
|
|
77
77
|
};
|
|
78
|
+
type AuthState = {
|
|
79
|
+
status: 'loading' | 'success' | 'errored';
|
|
80
|
+
error?: string;
|
|
81
|
+
};
|
|
78
82
|
|
|
79
83
|
declare class AuthConfigManager {
|
|
80
84
|
private static instance;
|
|
@@ -87,15 +91,7 @@ declare class AuthConfigManager {
|
|
|
87
91
|
initializeConfig(hasInitialSession: boolean): void;
|
|
88
92
|
}
|
|
89
93
|
declare const authConfigManager: AuthConfigManager;
|
|
90
|
-
declare const SessionContext: React$1.Context<
|
|
91
|
-
update: UpdateSession;
|
|
92
|
-
data: Session;
|
|
93
|
-
status: "authenticated";
|
|
94
|
-
} | {
|
|
95
|
-
update: UpdateSession;
|
|
96
|
-
data: null;
|
|
97
|
-
status: "unauthenticated" | "loading";
|
|
98
|
-
} | undefined>;
|
|
94
|
+
declare const SessionContext: React$1.Context<SessionContextValue | undefined>;
|
|
99
95
|
declare function getSession(params?: GetSessionParams): Promise<Session | null>;
|
|
100
96
|
declare function getCsrfToken(): Promise<string>;
|
|
101
97
|
declare function SessionProvider(props: SessionProviderProps): React$1.JSX.Element;
|
|
@@ -108,10 +104,9 @@ interface PopupLoginOptions extends Partial<Omit<WindowProps, 'url'>> {
|
|
|
108
104
|
onSuccess?: () => void;
|
|
109
105
|
callbackUrl?: string;
|
|
110
106
|
}
|
|
111
|
-
|
|
112
|
-
status: "loading" | "success" | "errored";
|
|
113
|
-
error?: string;
|
|
107
|
+
interface LoginState extends AuthState {
|
|
114
108
|
popUpSignin: () => Promise<void>;
|
|
115
|
-
}
|
|
109
|
+
}
|
|
110
|
+
declare const useOauthPopupLogin: (provider: Parameters<typeof signIn>[0], options?: PopupLoginOptions) => LoginState;
|
|
116
111
|
|
|
117
112
|
export { SessionContext, SessionProvider, authConfigManager, getCsrfToken, getProviders, getSession, signIn, signOut, useOauthPopupLogin, useSession };
|
package/dist/react.js
CHANGED
|
@@ -41,8 +41,12 @@ function useOnline() {
|
|
|
41
41
|
useEffect(() => {
|
|
42
42
|
const abortController = new AbortController();
|
|
43
43
|
const { signal } = abortController;
|
|
44
|
-
const setOnline = () =>
|
|
45
|
-
|
|
44
|
+
const setOnline = () => {
|
|
45
|
+
setIsOnline(true);
|
|
46
|
+
};
|
|
47
|
+
const setOffline = () => {
|
|
48
|
+
setIsOnline(false);
|
|
49
|
+
};
|
|
46
50
|
window.addEventListener("online", setOnline, { signal });
|
|
47
51
|
window.addEventListener("offline", setOffline, { signal });
|
|
48
52
|
return () => {
|
|
@@ -154,7 +158,9 @@ function useVisibilityChangeEventListener(authConfig, refetchOnWindowFocus) {
|
|
|
154
158
|
document.addEventListener("visibilitychange", handleVisibilityChange, {
|
|
155
159
|
signal: abortController.signal
|
|
156
160
|
});
|
|
157
|
-
return () =>
|
|
161
|
+
return () => {
|
|
162
|
+
abortController.abort();
|
|
163
|
+
};
|
|
158
164
|
}, [refetchOnWindowFocus]);
|
|
159
165
|
}
|
|
160
166
|
function useRefetchInterval(authConfig, refetchInterval, shouldRefetch) {
|
|
@@ -165,7 +171,9 @@ function useRefetchInterval(authConfig, refetchInterval, shouldRefetch) {
|
|
|
165
171
|
authConfig.fetchSession({ event: "poll" });
|
|
166
172
|
}
|
|
167
173
|
}, refetchInterval * 1e3);
|
|
168
|
-
return () =>
|
|
174
|
+
return () => {
|
|
175
|
+
clearInterval(intervalId);
|
|
176
|
+
};
|
|
169
177
|
}
|
|
170
178
|
}, [refetchInterval, shouldRefetch]);
|
|
171
179
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hono/auth-js",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "A third-party Auth js middleware for Hono",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -41,7 +41,8 @@
|
|
|
41
41
|
"prepack": "yarn build",
|
|
42
42
|
"publint": "attw --pack --profile node16 && publint",
|
|
43
43
|
"typecheck": "tsc -b tsconfig.json",
|
|
44
|
-
"test": "vitest"
|
|
44
|
+
"test": "vitest",
|
|
45
|
+
"version:jsr": "yarn version:set $npm_package_version"
|
|
45
46
|
},
|
|
46
47
|
"license": "MIT",
|
|
47
48
|
"publishConfig": {
|
|
@@ -55,19 +56,20 @@
|
|
|
55
56
|
},
|
|
56
57
|
"homepage": "https://github.com/honojs/middleware",
|
|
57
58
|
"peerDependencies": {
|
|
58
|
-
"@auth/core": "0
|
|
59
|
-
"hono": ">=3
|
|
59
|
+
"@auth/core": ">=0.35.0",
|
|
60
|
+
"hono": ">=3.0.0",
|
|
60
61
|
"react": "^18 || ^19 || ^19.0.0-rc"
|
|
61
62
|
},
|
|
62
63
|
"devDependencies": {
|
|
63
64
|
"@arethetypeswrong/cli": "^0.17.4",
|
|
64
65
|
"@auth/core": "^0.35.3",
|
|
65
66
|
"@types/react": "^18",
|
|
67
|
+
"hono": "^4.8.4",
|
|
66
68
|
"publint": "^0.3.9",
|
|
67
69
|
"react": "^18.2.0",
|
|
68
70
|
"tsup": "^8.4.0",
|
|
69
71
|
"typescript": "^5.8.2",
|
|
70
|
-
"vitest": "^3.
|
|
72
|
+
"vitest": "^3.2.4"
|
|
71
73
|
},
|
|
72
74
|
"engines": {
|
|
73
75
|
"node": ">=18.4.0"
|