@snokam/auth 6.0.8 → 6.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/CHANGELOG.md CHANGED
@@ -3,6 +3,12 @@
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
+ ## [6.0.9](https://github.com/snokam/components/compare/@snokam/auth@6.0.8...@snokam/auth@6.0.9) (2026-11-07)
7
+
8
+ ### Bug Fixes
9
+
10
+ - **web:** platform pages get the api base, so /manage works again ([#3270](https://github.com/snokam/components/issues/3270)) ([1f5ed27](https://github.com/snokam/components/commit/1f5ed279c6ddb80fc6733ea37c0322615bd7c64c))
11
+
6
12
  ## [6.0.8](https://github.com/snokam/components/compare/@snokam/auth@6.0.7...@snokam/auth@6.0.8) (2026-11-06)
7
13
 
8
14
  **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": "6.0.8",
4
+ "version": "6.0.9",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
7
7
  "files": [
@@ -25,12 +25,12 @@
25
25
  "@mui/material": "^9.2.0",
26
26
  "next-auth": "4.24.15",
27
27
  "path-to-regexp": "^8.4.2",
28
+ "@snokam/api-client": "1.0.0",
28
29
  "@snokam/identity": "1.1.0",
29
30
  "@snokam/page-content": "6.9.7",
30
31
  "@snokam/react-query": "1.1.0",
31
- "@snokam/ui": "7.2.2",
32
32
  "@snokam/tenant": "4.5.3",
33
- "@snokam/api-client": "1.0.0"
33
+ "@snokam/ui": "7.2.2"
34
34
  },
35
35
  "peerDependencies": {
36
36
  "next": "16.3.8",
@@ -4,6 +4,7 @@ import {
4
4
  isColorScheme,
5
5
  type ColorScheme,
6
6
  } from "./employee-profile";
7
+ import { profileIsStale } from "./profileAge";
7
8
  import { requestOrigin } from "./request";
8
9
  import { Auth } from "../types";
9
10
 
@@ -35,6 +36,7 @@ export function callbacks(config: Auth.Config): NextAuthOptions["callbacks"] {
35
36
  );
36
37
  if (employee.colorScheme) token.colorScheme = employee.colorScheme;
37
38
  token.picture = employee.imageUrl ?? null;
39
+ token.profileCheckedAt = Date.now();
38
40
  }
39
41
 
40
42
  const handoff = user as HandoffUser | undefined;
@@ -51,23 +53,28 @@ export function callbacks(config: Auth.Config): NextAuthOptions["callbacks"] {
51
53
  );
52
54
  if (employee.colorScheme) token.colorScheme = employee.colorScheme;
53
55
  if (employee.imageUrl) token.picture = employee.imageUrl;
56
+ token.profileCheckedAt = Date.now();
54
57
  }
55
58
 
56
- if (trigger === "update") {
57
- if (isColorScheme(session?.colorScheme))
58
- token.colorScheme = session.colorScheme;
59
+ if (trigger === "update" && isColorScheme(session?.colorScheme))
60
+ token.colorScheme = session.colorScheme;
59
61
 
60
- if (session?.refreshProfile && token.refreshToken) {
61
- const employee = await fetchEmployeeProfile(
62
- {
63
- ...config,
64
- tenantId: (token.tid as string | undefined) ?? config.tenantId,
65
- },
66
- token.refreshToken as string,
67
- token.authMethod as string | undefined
68
- );
69
- if (employee.imageUrl) token.picture = employee.imageUrl;
70
- }
62
+ const refreshRequested =
63
+ trigger === "update" && !!session?.refreshProfile;
64
+ if (
65
+ token.refreshToken &&
66
+ (refreshRequested || profileIsStale(token.profileCheckedAt, Date.now()))
67
+ ) {
68
+ const employee = await fetchEmployeeProfile(
69
+ {
70
+ ...config,
71
+ tenantId: (token.tid as string | undefined) ?? config.tenantId,
72
+ },
73
+ token.refreshToken as string,
74
+ token.authMethod as string | undefined
75
+ );
76
+ if (employee.imageUrl) token.picture = employee.imageUrl;
77
+ token.profileCheckedAt = Date.now();
71
78
  }
72
79
 
73
80
  return token;
@@ -0,0 +1,19 @@
1
+ import assert from "node:assert/strict";
2
+ import { describe, it } from "node:test";
3
+ import { PROFILE_MAX_AGE_MS, profileIsStale } from "./profileAge.ts";
4
+
5
+ describe("the profile a session carries", () => {
6
+ const now = 1_800_000_000_000;
7
+
8
+ it("is fetched again when the session never recorded when it was read", () => {
9
+ assert.equal(profileIsStale(undefined, now), true);
10
+ });
11
+
12
+ it("is kept while it is younger than a day", () => {
13
+ assert.equal(profileIsStale(now - PROFILE_MAX_AGE_MS + 1, now), false);
14
+ });
15
+
16
+ it("is fetched again once it is a day old", () => {
17
+ assert.equal(profileIsStale(now - PROFILE_MAX_AGE_MS, now), true);
18
+ });
19
+ });
@@ -0,0 +1,5 @@
1
+ export const PROFILE_MAX_AGE_MS = 24 * 60 * 60 * 1000;
2
+
3
+ export function profileIsStale(checkedAt: unknown, now: number): boolean {
4
+ return typeof checkedAt !== "number" || now - checkedAt >= PROFILE_MAX_AGE_MS;
5
+ }