najm-auth 6.0.0 → 6.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/README.md +1372 -1372
- package/dist/client/react/index.d.ts +17 -1
- package/dist/client/react/index.js +11 -0
- package/package.json +3 -3
|
@@ -216,6 +216,22 @@ declare function useOAuthCallback(options?: UseOAuthCallbackOptions): {
|
|
|
216
216
|
*/
|
|
217
217
|
declare function useAuthEvent<K extends AuthEvent>(event: K, handler: (data: AuthEventMap[K]) => void): void;
|
|
218
218
|
|
|
219
|
+
/**
|
|
220
|
+
* Sends the user to sign in when the session ends while a page is open.
|
|
221
|
+
*
|
|
222
|
+
* A server page checks the session only when it renders, so a session revoked
|
|
223
|
+
* or expired afterwards leaves the page up: every read then answers 401, and a
|
|
224
|
+
* list shows as empty instead of asking the user to sign in again.
|
|
225
|
+
*
|
|
226
|
+
* It is a full navigation, so the auth middleware can clear the dead cookies,
|
|
227
|
+
* and `from` brings the user back to this page afterwards, as the middleware's
|
|
228
|
+
* own redirect does. A normal sign-out emits `logout`, not `sessionExpired`,
|
|
229
|
+
* so the sign-out button keeps its own navigation.
|
|
230
|
+
*
|
|
231
|
+
* Mount it once, in the layout every signed-in page shares.
|
|
232
|
+
*/
|
|
233
|
+
declare function useRedirectOnSessionExpired(loginRoute?: string): void;
|
|
234
|
+
|
|
219
235
|
interface AuthEventEntry {
|
|
220
236
|
event: AuthEvent;
|
|
221
237
|
data: unknown;
|
|
@@ -600,4 +616,4 @@ interface OAuthCallbackProps {
|
|
|
600
616
|
}
|
|
601
617
|
declare function OAuthCallback({ fallback, errorFallback, defaultRedirect, }: OAuthCallbackProps): react.JSX.Element;
|
|
602
618
|
|
|
603
|
-
export { AuthBoundary, type AuthEventEntry, AuthGate, AuthLoading, AuthProvider, Can, GitHubLoginButton, GoogleLoginButton, IfAuth, LoginButton, OAuthCallback, PermissionList, Protected, RedirectToLogin, Role, type SessionStatus, SignOutButton, SignedIn, SignedOut, UserAvatar, UserEmail, UserName, UserRole, useAuth, useAuthClient, useAuthEvent, useAuthEvents, useChangePassword, useForgotPassword, useGitHubLogin, useGoogleLogin, useLogin, useLogout, useOAuthCallback, usePermissions, useRegister, useResetPassword, useSession, useUser };
|
|
619
|
+
export { AuthBoundary, type AuthEventEntry, AuthGate, AuthLoading, AuthProvider, Can, GitHubLoginButton, GoogleLoginButton, IfAuth, LoginButton, OAuthCallback, PermissionList, Protected, RedirectToLogin, Role, type SessionStatus, SignOutButton, SignedIn, SignedOut, UserAvatar, UserEmail, UserName, UserRole, useAuth, useAuthClient, useAuthEvent, useAuthEvents, useChangePassword, useForgotPassword, useGitHubLogin, useGoogleLogin, useLogin, useLogout, useOAuthCallback, usePermissions, useRedirectOnSessionExpired, useRegister, useResetPassword, useSession, useUser };
|
|
@@ -431,6 +431,16 @@ function useAuthEvent(event, handler) {
|
|
|
431
431
|
}
|
|
432
432
|
__name(useAuthEvent, "useAuthEvent");
|
|
433
433
|
|
|
434
|
+
// src/client/react/useRedirectOnSessionExpired.ts
|
|
435
|
+
function useRedirectOnSessionExpired(loginRoute = "/login") {
|
|
436
|
+
useAuthEvent("sessionExpired", () => {
|
|
437
|
+
const login = new URL(loginRoute, window.location.origin);
|
|
438
|
+
login.searchParams.set("from", `${window.location.pathname}${window.location.search}`);
|
|
439
|
+
window.location.assign(login.toString());
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
__name(useRedirectOnSessionExpired, "useRedirectOnSessionExpired");
|
|
443
|
+
|
|
434
444
|
// src/client/react/useAuthEvents.ts
|
|
435
445
|
import { useEffect as useEffect4, useRef as useRef5, useState as useState12 } from "react";
|
|
436
446
|
var ALL_EVENTS = [
|
|
@@ -845,6 +855,7 @@ export {
|
|
|
845
855
|
useLogout,
|
|
846
856
|
useOAuthCallback,
|
|
847
857
|
usePermissions,
|
|
858
|
+
useRedirectOnSessionExpired,
|
|
848
859
|
useRegister,
|
|
849
860
|
useResetPassword,
|
|
850
861
|
useSession,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "najm-auth",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.1.0",
|
|
4
4
|
"description": "Authentication and authorization library for najm framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -93,8 +93,8 @@
|
|
|
93
93
|
"dependencies": {
|
|
94
94
|
"bcryptjs": "^3.0.2",
|
|
95
95
|
"najm-cookies": "^2.0.3",
|
|
96
|
-
"najm-core": "^3.0.
|
|
97
|
-
"najm-database": "^2.2.
|
|
96
|
+
"najm-core": "^3.0.4",
|
|
97
|
+
"najm-database": "^2.2.1",
|
|
98
98
|
"najm-guard": "^2.2.1",
|
|
99
99
|
"najm-i18n": "^2.1.3",
|
|
100
100
|
"najm-cache": "^2.2.0",
|