@snokam/auth 3.3.7 → 3.3.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/CHANGELOG.md +10 -0
- package/package.json +4 -4
- package/src/app-router/components/Provider/index.tsx +9 -6
- package/src/app-router/index.tsx +1 -0
- package/src/components/Authenticated.tsx +1 -1
- package/src/components/Unauthenticated.tsx +1 -1
- package/src/hooks.ts +2 -1
- package/src/index.ts +1 -0
- package/src/session/useSession.ts +39 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,16 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [3.3.9](https://github.com/snokam/components/compare/@snokam/auth@3.3.8...@snokam/auth@3.3.9) (2026-10-05)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- **auth,head,events-web:** hydrate with the server's auth state, stop iOS rewriting text, deterministic cover memory ([#2663](https://github.com/snokam/components/issues/2663)) ([1a8e7ef](https://github.com/snokam/components/commit/1a8e7ef8ea0f38fb3a56d36cc49ed22373d6f11b)), closes [#418](https://github.com/snokam/components/issues/418)
|
|
11
|
+
|
|
12
|
+
## [3.3.8](https://github.com/snokam/components/compare/@snokam/auth@3.3.7...@snokam/auth@3.3.8) (2026-10-05)
|
|
13
|
+
|
|
14
|
+
**Note:** Version bump only for package @snokam/auth
|
|
15
|
+
|
|
6
16
|
## [3.3.7](https://github.com/snokam/components/compare/@snokam/auth@3.3.6...@snokam/auth@3.3.7) (2026-10-05)
|
|
7
17
|
|
|
8
18
|
**Note:** Version bump only for package @snokam/auth
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@snokam/auth",
|
|
3
3
|
"description": "Snøkam auth components",
|
|
4
|
-
"version": "3.3.
|
|
4
|
+
"version": "3.3.9",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"types": "src/index.ts",
|
|
7
7
|
"files": [
|
|
@@ -26,10 +26,10 @@
|
|
|
26
26
|
"next-auth": "4.24.15",
|
|
27
27
|
"path-to-regexp": "^8.4.2",
|
|
28
28
|
"@snokam/identity": "1.1.0",
|
|
29
|
-
"@snokam/platform-client": "3.
|
|
29
|
+
"@snokam/platform-client": "3.5.0",
|
|
30
30
|
"@snokam/react-query": "1.1.0",
|
|
31
|
-
"@snokam/
|
|
32
|
-
"@snokam/
|
|
31
|
+
"@snokam/ui": "4.0.0",
|
|
32
|
+
"@snokam/tenant": "2.1.11"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
35
|
"next": "16.3.3",
|
|
@@ -7,17 +7,20 @@ import { Authenticate } from "../../../components/Authenticate";
|
|
|
7
7
|
import { SessionProvider } from "next-auth/react";
|
|
8
8
|
import { useAuth } from "../../../hooks";
|
|
9
9
|
import { EmployeeThemeSync } from "../../../theme/employee-theme-sync";
|
|
10
|
+
import { ServerSessionContext } from "../../../session/useSession";
|
|
10
11
|
|
|
11
12
|
export const Provider = memo((props: Auth.Provider.Props) => {
|
|
12
13
|
const { session, children } = props;
|
|
13
14
|
|
|
14
15
|
return (
|
|
15
|
-
<
|
|
16
|
-
<
|
|
17
|
-
|
|
18
|
-
<
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
<ServerSessionContext.Provider value={session ?? null}>
|
|
17
|
+
<SessionProvider session={session ?? undefined}>
|
|
18
|
+
<EmployeeThemeSync />
|
|
19
|
+
<Suspense fallback={<>{children}</>}>
|
|
20
|
+
<ProviderInner {...props}>{children}</ProviderInner>
|
|
21
|
+
</Suspense>
|
|
22
|
+
</SessionProvider>
|
|
23
|
+
</ServerSessionContext.Provider>
|
|
21
24
|
);
|
|
22
25
|
});
|
|
23
26
|
|
package/src/app-router/index.tsx
CHANGED
|
@@ -11,6 +11,7 @@ import { EmployeeGate } from "../components/EmployeeGate";
|
|
|
11
11
|
export { Unauthenticated } from "../components/Unauthenticated";
|
|
12
12
|
export { Authenticated } from "../components/Authenticated";
|
|
13
13
|
export { useAuth } from "../hooks";
|
|
14
|
+
export { useSession } from "../session/useSession";
|
|
14
15
|
export { EmployeeThemeSync } from "../theme/employee-theme-sync";
|
|
15
16
|
export { ScopesProvider, useScopes, useHasScope } from "../scopes";
|
|
16
17
|
export {
|
package/src/hooks.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { signIn, signOut } from "next-auth/react";
|
|
2
2
|
import { useMemo } from "react";
|
|
3
3
|
import { IMP_ACTIVE_COOKIE } from "./impersonation/cookies";
|
|
4
4
|
import { useImpersonation } from "./impersonation/context";
|
|
5
|
+
import { useSession } from "./session/useSession";
|
|
5
6
|
|
|
6
7
|
class ConsentRequiredError extends Error {}
|
|
7
8
|
|
package/src/index.ts
CHANGED
|
@@ -2,6 +2,7 @@ export * from "./components";
|
|
|
2
2
|
export * from "./scopes";
|
|
3
3
|
|
|
4
4
|
export { useAuth, clearAuthTokenCache } from "./hooks";
|
|
5
|
+
export { useSession } from "./session/useSession";
|
|
5
6
|
|
|
6
7
|
export { buildAdminConsentUrl } from "./consent";
|
|
7
8
|
export type { AdminConsentParams } from "./consent";
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { createContext, useContext, useSyncExternalStore } from "react";
|
|
4
|
+
import {
|
|
5
|
+
useSession as useLiveSession,
|
|
6
|
+
type SessionContextValue,
|
|
7
|
+
} from "next-auth/react";
|
|
8
|
+
import type { Session } from "next-auth";
|
|
9
|
+
|
|
10
|
+
export const ServerSessionContext = createContext<Session | null>(null);
|
|
11
|
+
|
|
12
|
+
const subscribeToNothing = () => () => {};
|
|
13
|
+
|
|
14
|
+
const useIsHydrating = () =>
|
|
15
|
+
useSyncExternalStore(
|
|
16
|
+
subscribeToNothing,
|
|
17
|
+
() => false,
|
|
18
|
+
() => true
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
export const useSession = (): SessionContextValue => {
|
|
22
|
+
const liveSession = useLiveSession();
|
|
23
|
+
const serverSession = useContext(ServerSessionContext);
|
|
24
|
+
const hydrating = useIsHydrating();
|
|
25
|
+
|
|
26
|
+
if (!hydrating) {
|
|
27
|
+
return liveSession;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (!serverSession) {
|
|
31
|
+
return { update: liveSession.update, data: null, status: "loading" };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
update: liveSession.update,
|
|
36
|
+
data: serverSession,
|
|
37
|
+
status: "authenticated",
|
|
38
|
+
};
|
|
39
|
+
};
|