@snokam/auth 6.1.16 → 6.3.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/package.json +7 -6
- package/src/middleware.tsx +3 -16
- package/src/public-paths.test.ts +31 -0
- package/src/public-paths.ts +17 -0
- package/src/types.ts +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,18 @@
|
|
|
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.0](https://github.com/snokam/components/compare/%40snokam%2Fauth%406.2.0...%40snokam%2Fauth%406.3.0) (2026-11-12)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
- **content:** a content editor with drafts, history and click-to-edit on real pages ([#3579](https://github.com/snokam/components/issues/3579)) ([11bcf8e](https://github.com/snokam/components/commit/11bcf8eb7ae94a98bc4137e0da5b01df8b446356))
|
|
11
|
+
|
|
12
|
+
# [6.2.0](https://github.com/snokam/components/compare/%40snokam%2Fauth%406.1.16...%40snokam%2Fauth%406.2.0) (2026-11-12)
|
|
13
|
+
|
|
14
|
+
### Features
|
|
15
|
+
|
|
16
|
+
- **native:** one bar, kept-alive tabs, back navigation and the web's icons in the app ([#3586](https://github.com/snokam/components/issues/3586)) ([1929ffc](https://github.com/snokam/components/commit/1929ffc44cfc1803134de665d6061cbd0b13f250))
|
|
17
|
+
|
|
6
18
|
## [6.1.16](https://github.com/snokam/components/compare/%40snokam%2Fauth%406.1.15...%40snokam%2Fauth%406.1.16) (2026-11-11)
|
|
7
19
|
|
|
8
20
|
**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.
|
|
4
|
+
"version": "6.3.0",
|
|
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.
|
|
29
|
+
"@snokam/page-content": "6.11.0",
|
|
30
|
+
"@snokam/identity": "1.1.1",
|
|
30
31
|
"@snokam/react-query": "1.1.1",
|
|
31
|
-
"@snokam/api-client": "1.0.0",
|
|
32
32
|
"@snokam/tenant": "4.5.7",
|
|
33
|
-
"@snokam/
|
|
34
|
-
"@snokam/
|
|
33
|
+
"@snokam/ui": "7.9.0",
|
|
34
|
+
"@snokam/api-client": "1.0.0"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
37
|
"next": "16.4.5",
|
|
@@ -50,7 +50,8 @@
|
|
|
50
50
|
"./app-router": "./src/app-router/index.tsx",
|
|
51
51
|
"./app-router/server": "./src/app-router/server.ts",
|
|
52
52
|
"./password": "./src/password/api.ts",
|
|
53
|
-
"./sso-tenant": "./src/sso/tenant-cookie.ts"
|
|
53
|
+
"./sso-tenant": "./src/sso/tenant-cookie.ts",
|
|
54
|
+
"./scopes": "./src/scopes/matcher.ts"
|
|
54
55
|
},
|
|
55
56
|
"scripts": {
|
|
56
57
|
"lint": "eslint .",
|
package/src/middleware.tsx
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { match } from "path-to-regexp";
|
|
2
|
+
import { isAlwaysPublic } from "./public-paths";
|
|
2
3
|
import { getToken } from "next-auth/jwt";
|
|
3
4
|
import { type NextRequestWithAuth } from "next-auth/middleware";
|
|
4
5
|
import { NextResponse, NextFetchEvent } from "next/server";
|
|
@@ -23,17 +24,11 @@ function withoutImpersonation(
|
|
|
23
24
|
return response;
|
|
24
25
|
}
|
|
25
26
|
|
|
26
|
-
const LOGIN_FLOW_PATHS = [
|
|
27
|
-
"/auth/",
|
|
28
|
-
"/handoff/",
|
|
29
|
-
"/api/password/",
|
|
30
|
-
"/api/impersonation/adopt",
|
|
31
|
-
];
|
|
32
|
-
|
|
33
27
|
export function buildAuthMiddleware({
|
|
34
28
|
matcher = [],
|
|
35
29
|
callbacks = {},
|
|
36
30
|
protectAllRoutes,
|
|
31
|
+
publicPaths: appPublicPaths = [],
|
|
37
32
|
cors = {},
|
|
38
33
|
...rest
|
|
39
34
|
}: Auth.Middleware.Props = {}): Auth.Middleware.Builder {
|
|
@@ -43,15 +38,7 @@ export function buildAuthMiddleware({
|
|
|
43
38
|
const { name } = getSessionCookieSettings(getAuthUrl());
|
|
44
39
|
|
|
45
40
|
const shouldProtectPath = (pathname: string): boolean => {
|
|
46
|
-
if (pathname
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (pathname.startsWith("/api/ready")) {
|
|
51
|
-
return false;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
if (LOGIN_FLOW_PATHS.some((path) => pathname.startsWith(path))) {
|
|
41
|
+
if (isAlwaysPublic(pathname, appPublicPaths)) {
|
|
55
42
|
return false;
|
|
56
43
|
}
|
|
57
44
|
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { describe, it } from "node:test";
|
|
3
|
+
import { isAlwaysPublic } from "./public-paths.ts";
|
|
4
|
+
|
|
5
|
+
describe("paths that never need a login", () => {
|
|
6
|
+
it("include health probes and the login flow", () => {
|
|
7
|
+
for (const path of [
|
|
8
|
+
"/api/healthy",
|
|
9
|
+
"/api/ready",
|
|
10
|
+
"/auth/login",
|
|
11
|
+
"/handoff/start",
|
|
12
|
+
"/api/password/login",
|
|
13
|
+
"/api/impersonation/adopt",
|
|
14
|
+
]) {
|
|
15
|
+
assert.equal(isAlwaysPublic(path), true, path);
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it("include the paths an app declares public, exactly", () => {
|
|
20
|
+
const appPaths = ["/api/menu", "/api/push/config"];
|
|
21
|
+
assert.equal(isAlwaysPublic("/api/menu", appPaths), true);
|
|
22
|
+
assert.equal(isAlwaysPublic("/api/push/config", appPaths), true);
|
|
23
|
+
assert.equal(isAlwaysPublic("/api/menu/admin", appPaths), false);
|
|
24
|
+
assert.equal(isAlwaysPublic("/oppgaver", appPaths), false);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("exclude everything else", () => {
|
|
28
|
+
assert.equal(isAlwaysPublic("/api/menu"), false);
|
|
29
|
+
assert.equal(isAlwaysPublic("/"), false);
|
|
30
|
+
});
|
|
31
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const PROBES = ["/api/healthy", "/api/ready"];
|
|
2
|
+
|
|
3
|
+
const LOGIN_FLOW_PATHS = [
|
|
4
|
+
"/auth/",
|
|
5
|
+
"/handoff/",
|
|
6
|
+
"/api/password/",
|
|
7
|
+
"/api/impersonation/adopt",
|
|
8
|
+
];
|
|
9
|
+
|
|
10
|
+
export function isAlwaysPublic(
|
|
11
|
+
pathname: string,
|
|
12
|
+
appPublicPaths: readonly string[] = []
|
|
13
|
+
): boolean {
|
|
14
|
+
if (PROBES.some((path) => pathname.startsWith(path))) return true;
|
|
15
|
+
if (LOGIN_FLOW_PATHS.some((path) => pathname.startsWith(path))) return true;
|
|
16
|
+
return appPublicPaths.includes(pathname);
|
|
17
|
+
}
|