@snokam/auth 6.3.11 → 6.3.12

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.3.12](https://github.com/snokam/components/compare/%40snokam%2Fauth%406.3.11...%40snokam%2Fauth%406.3.12) (2026-11-14)
7
+
8
+ ### Bug Fixes
9
+
10
+ - **auth:** stop retrying /me on client errors and probing with the wrong identity ([#3708](https://github.com/snokam/components/issues/3708)) ([1bf6163](https://github.com/snokam/components/commit/1bf616328370880feaf9c50a4972c4553a0eb1b8))
11
+
6
12
  ## [6.3.11](https://github.com/snokam/components/compare/%40snokam%2Fauth%406.3.10...%40snokam%2Fauth%406.3.11) (2026-11-13)
7
13
 
8
14
  ### Performance Improvements
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.3.11",
4
+ "version": "6.3.12",
5
5
  "main": "src/index.ts",
6
6
  "sideEffects": false,
7
7
  "types": "src/index.ts",
@@ -26,12 +26,12 @@
26
26
  "@mui/material": "^9.5.0",
27
27
  "next-auth": "4.24.15",
28
28
  "path-to-regexp": "^9.0.0",
29
- "@snokam/page-content": "6.12.8",
30
29
  "@snokam/api-client": "1.0.0",
31
- "@snokam/tenant": "4.5.7",
32
- "@snokam/ui": "7.11.0",
30
+ "@snokam/identity": "1.1.1",
31
+ "@snokam/page-content": "6.12.9",
33
32
  "@snokam/react-query": "1.1.3",
34
- "@snokam/identity": "1.1.1"
33
+ "@snokam/tenant": "4.5.8",
34
+ "@snokam/ui": "7.11.0"
35
35
  },
36
36
  "peerDependencies": {
37
37
  "next": "16.4.5",
@@ -0,0 +1,31 @@
1
+ import assert from "node:assert/strict";
2
+ import { describe, it } from "node:test";
3
+ import { retryUnlessMissing } from "./retry.ts";
4
+
5
+ function failed(status: number) {
6
+ return { response: { status } };
7
+ }
8
+
9
+ describe("retrying the signed-in employee", () => {
10
+ for (const status of [400, 401, 403, 404, 409, 422]) {
11
+ it(`gives up at once on ${status}, which the next try would repeat`, () => {
12
+ assert.equal(retryUnlessMissing(0, failed(status)), false);
13
+ });
14
+ }
15
+
16
+ for (const status of [408, 429, 500, 502, 503]) {
17
+ it(`tries again on ${status}`, () => {
18
+ assert.equal(retryUnlessMissing(0, failed(status)), true);
19
+ });
20
+ }
21
+
22
+ it("tries again when the request never got an answer", () => {
23
+ assert.equal(retryUnlessMissing(0, new TypeError("Failed to fetch")), true);
24
+ assert.equal(retryUnlessMissing(0, null), true);
25
+ });
26
+
27
+ it("stops after three tries", () => {
28
+ assert.equal(retryUnlessMissing(2, failed(503)), true);
29
+ assert.equal(retryUnlessMissing(3, failed(503)), false);
30
+ });
31
+ });
@@ -1,9 +1,15 @@
1
1
  const MAX_RETRIES = 3;
2
+ const RETRIED_CLIENT_ERRORS = new Set([408, 429]);
2
3
 
3
4
  function responseStatus(error: unknown): number | undefined {
4
5
  return (error as { response?: { status?: number } } | null)?.response?.status;
5
6
  }
6
7
 
8
+ function isLasting(status: number | undefined): boolean {
9
+ if (status === undefined || RETRIED_CLIENT_ERRORS.has(status)) return false;
10
+ return status >= 400 && status < 500;
11
+ }
12
+
7
13
  export function retryUnlessMissing(failureCount: number, error: unknown) {
8
- return responseStatus(error) !== 404 && failureCount < MAX_RETRIES;
14
+ return !isLasting(responseStatus(error)) && failureCount < MAX_RETRIES;
9
15
  }
@@ -2,7 +2,11 @@
2
2
 
3
3
  import { useEffect, useMemo } from "react";
4
4
  import { Configuration, EmployeesClient } from "@snokam/api-client/employees";
5
- import { apiBaseUrl, useOptionalConfig } from "@snokam/tenant";
5
+ import {
6
+ apiBaseUrl,
7
+ apiServesPlatformTemplate,
8
+ useOptionalConfig,
9
+ } from "@snokam/tenant";
6
10
  import { useClientQuery } from "@snokam/react-query";
7
11
  import { useAdminTheme } from "@snokam/ui/theme/admin";
8
12
  import type { ColorSchemeMode } from "@snokam/ui/theme/admin";
@@ -21,6 +25,8 @@ export default function SavedThemeSync() {
21
25
  const config = useOptionalConfig();
22
26
 
23
27
  const basePath = config ? apiBaseUrl(config) : undefined;
28
+ const hasEmployees =
29
+ !!config && !!basePath && !apiServesPlatformTemplate(config);
24
30
  const client = useMemo(
25
31
  () =>
26
32
  new EmployeesClient(
@@ -38,13 +44,13 @@ export default function SavedThemeSync() {
38
44
  }).useGetMeProtectedQuery(
39
45
  {},
40
46
  {
41
- enabled: isAuthenticated && !!basePath,
47
+ enabled: isAuthenticated && hasEmployees,
42
48
  retry: retryUnlessMissing,
43
49
  }
44
50
  );
45
51
 
46
52
  const saved = data?.settings?.colorScheme;
47
- const settled = isSuccess || isError || !basePath;
53
+ const settled = isSuccess || isError || !hasEmployees;
48
54
 
49
55
  useEffect(() => {
50
56
  if (isMode(saved)) seedMode(saved);