@wtfalch/auth 0.1.1 → 0.2.1
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/dist/auth.d.ts +2 -2
- package/dist/auth.js +13 -0
- package/dist/broker.d.ts +6 -0
- package/dist/redirect.js +8 -1
- package/package.json +12 -11
package/dist/auth.d.ts
CHANGED
|
@@ -37,9 +37,9 @@ export type Gate = {
|
|
|
37
37
|
cookies: SetCookie[];
|
|
38
38
|
};
|
|
39
39
|
export type Intent = 'login' | 'register';
|
|
40
|
-
export type SignInError = 'invalid_credentials' | 'request' | 'unavailable';
|
|
40
|
+
export type SignInError = 'invalid_credentials' | 'too_many' | 'request' | 'unavailable';
|
|
41
41
|
export type ResetError = 'invalid_code' | 'invalid_password' | 'unavailable';
|
|
42
|
-
export type SignUpError = 'email_taken' | 'invalid' | 'request' | 'unavailable';
|
|
42
|
+
export type SignUpError = 'registration_closed' | 'email_taken' | 'username_taken' | 'username_invalid' | 'invalid' | 'request' | 'unavailable';
|
|
43
43
|
export type SignInResult = {
|
|
44
44
|
ok: true;
|
|
45
45
|
redirectTo: string;
|
package/dist/auth.js
CHANGED
|
@@ -265,6 +265,16 @@ export function createAuth(input) {
|
|
|
265
265
|
if (error instanceof BrokerError && error.error === 'email_taken') {
|
|
266
266
|
return { ok: false, error: 'email_taken', message: error.detail ?? error.error };
|
|
267
267
|
}
|
|
268
|
+
if (error instanceof BrokerError && error.error === 'registration_closed') {
|
|
269
|
+
return { ok: false, error: 'registration_closed', message: error.detail ?? error.error };
|
|
270
|
+
}
|
|
271
|
+
// Both carry a sentence about the name, for the form to show as it is.
|
|
272
|
+
if (error instanceof BrokerError && error.error === 'username_taken') {
|
|
273
|
+
return { ok: false, error: 'username_taken', message: error.detail ?? error.error };
|
|
274
|
+
}
|
|
275
|
+
if (error instanceof BrokerError && error.error === 'username_invalid') {
|
|
276
|
+
return { ok: false, error: 'username_invalid', message: error.detail ?? error.error };
|
|
277
|
+
}
|
|
268
278
|
if (error instanceof BrokerError && error.error === 'request') {
|
|
269
279
|
return { ok: false, error: 'request', message: error.detail ?? error.error };
|
|
270
280
|
}
|
|
@@ -390,6 +400,9 @@ function signInError(error) {
|
|
|
390
400
|
// A key the service will not take is the app's problem, not the visitor's.
|
|
391
401
|
if (error instanceof BrokerError && error.error === 'unauthorized')
|
|
392
402
|
return 'unavailable';
|
|
403
|
+
// The sign-in service's brute-force backstop tripped; ask them to wait.
|
|
404
|
+
if (error instanceof BrokerError && error.error === 'too_many')
|
|
405
|
+
return 'too_many';
|
|
393
406
|
if (error instanceof BrokerError && error.status < 500)
|
|
394
407
|
return 'invalid_credentials';
|
|
395
408
|
return 'unavailable';
|
package/dist/broker.d.ts
CHANGED
|
@@ -9,6 +9,12 @@ export interface NewUser {
|
|
|
9
9
|
password: string;
|
|
10
10
|
givenName: string;
|
|
11
11
|
familyName: string;
|
|
12
|
+
/**
|
|
13
|
+
* A login name they chose, where the app asks for one. Three to thirty of
|
|
14
|
+
* letters, digits, `.`, `_` and `-`; the service refuses reserved names
|
|
15
|
+
* and words it will not have. Without it the email is the login name.
|
|
16
|
+
*/
|
|
17
|
+
username?: string;
|
|
12
18
|
}
|
|
13
19
|
export declare class BrokerError extends Error {
|
|
14
20
|
readonly status: number;
|
package/dist/redirect.js
CHANGED
|
@@ -12,5 +12,12 @@ export function safeNextPath(next, fallback) {
|
|
|
12
12
|
}
|
|
13
13
|
if (url.origin !== 'https://app.invalid')
|
|
14
14
|
return fallback;
|
|
15
|
-
|
|
15
|
+
const path = `${url.pathname}${url.search}`;
|
|
16
|
+
// The URL parser can normalise an input like "/..//evil" into a
|
|
17
|
+
// protocol-relative "//evil", which a caller resolving it against an origin
|
|
18
|
+
// would send to another host. Guard the OUTPUT, not just the input.
|
|
19
|
+
if (!path.startsWith('/') || path.startsWith('//') || path.startsWith('/\\')) {
|
|
20
|
+
return fallback;
|
|
21
|
+
}
|
|
22
|
+
return path;
|
|
16
23
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wtfalch/auth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Sign in against auth.wtfalch.dev from a Next.js app.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -8,7 +8,9 @@
|
|
|
8
8
|
"directory": "packages/auth"
|
|
9
9
|
},
|
|
10
10
|
"type": "module",
|
|
11
|
-
"files": [
|
|
11
|
+
"files": [
|
|
12
|
+
"dist"
|
|
13
|
+
],
|
|
12
14
|
"exports": {
|
|
13
15
|
".": {
|
|
14
16
|
"types": "./dist/index.d.ts",
|
|
@@ -23,12 +25,6 @@
|
|
|
23
25
|
"engines": {
|
|
24
26
|
"node": ">=22.0.0"
|
|
25
27
|
},
|
|
26
|
-
"scripts": {
|
|
27
|
-
"build": "rm -rf dist && tsc -p tsconfig.build.json",
|
|
28
|
-
"prepack": "pnpm build",
|
|
29
|
-
"typecheck": "tsc --noEmit",
|
|
30
|
-
"test": "vitest run"
|
|
31
|
-
},
|
|
32
28
|
"dependencies": {
|
|
33
29
|
"jose": "^6.2.10",
|
|
34
30
|
"openid-client": "6.8.7"
|
|
@@ -44,11 +40,16 @@
|
|
|
44
40
|
"devDependencies": {
|
|
45
41
|
"@types/node": "^22",
|
|
46
42
|
"@types/react": "^19",
|
|
47
|
-
"@wtfalch/auth-broker": "workspace:*",
|
|
48
43
|
"next": "^16",
|
|
49
44
|
"playwright-core": "^1.62.1",
|
|
50
45
|
"react": "^19",
|
|
51
46
|
"typescript": "^5.9.0",
|
|
52
|
-
"vitest": "^4.1.6"
|
|
47
|
+
"vitest": "^4.1.6",
|
|
48
|
+
"@wtfalch/auth-broker": "0.1.0"
|
|
49
|
+
},
|
|
50
|
+
"scripts": {
|
|
51
|
+
"build": "rm -rf dist && tsc -p tsconfig.build.json",
|
|
52
|
+
"typecheck": "tsc --noEmit",
|
|
53
|
+
"test": "vitest run"
|
|
53
54
|
}
|
|
54
|
-
}
|
|
55
|
+
}
|