@kayjs/auth 1.104.3 → 1.106.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/llms/admin-and-organizations.md +8 -8
- package/llms/admin-pages.md +2 -2
- package/llms/grouped-methods.md +33 -17
- package/llms/hardening-and-testing.md +9 -9
- package/llms/oauth-passkeys-two-factor.md +14 -14
- package/llms/oauth-providers.md +1 -1
- package/llms/oauth-server-and-tokens.md +7 -7
- package/llms/passwords-and-mails.md +15 -15
- package/llms/sessions-and-guards.md +9 -1
- package/llms/setup.md +6 -6
- package/llms/signed-in-components.md +20 -11
- package/llms.txt +1 -1
- package/package.json +10 -6
- package/src/account.ts +6 -15
- package/src/admin.ts +9 -25
- package/src/auth.ts +9 -6
- package/src/authorize/clients.ts +1 -1
- package/src/authorize/grants.ts +2 -4
- package/src/authorize/request.ts +2 -4
- package/src/bearer.ts +5 -11
- package/src/captcha.ts +5 -3
- package/src/components/sign-in-link.kay +19 -0
- package/src/components/sign-out-button.kay +17 -0
- package/src/components/signed-in.kay +7 -2
- package/src/components/user-menu.kay +11 -8
- package/src/context.ts +1 -1
- package/src/deletion.ts +2 -4
- package/src/email.ts +16 -28
- package/src/erase.ts +5 -4
- package/src/export.ts +2 -4
- package/src/failure.ts +37 -9
- package/src/guard.ts +8 -1
- package/src/guards.ts +12 -5
- package/src/index.ts +14 -16
- package/src/limits.ts +97 -5
- package/src/mail.ts +5 -3
- package/src/memoryStore.ts +6 -6
- package/src/messages/fr.ts +1 -0
- package/src/methods/account.ts +30 -14
- package/src/methods/admin.ts +31 -14
- package/src/methods/captcha.ts +18 -0
- package/src/methods/email.ts +16 -7
- package/src/methods/magicLink.ts +5 -5
- package/src/methods/oauth.ts +16 -7
- package/src/methods/oauthServer.ts +32 -6
- package/src/methods/organizations.ts +51 -20
- package/src/methods/passkeys.ts +13 -7
- package/src/methods/password.ts +10 -10
- package/src/methods/proof.ts +22 -0
- package/src/methods/sessions.ts +3 -2
- package/src/methods/tokens.ts +17 -5
- package/src/methods/twoFactor.ts +10 -10
- package/src/oauth/flow.ts +2 -4
- package/src/oauth/providers.ts +1 -1
- package/src/oauthTest.ts +8 -4
- package/src/organizations.ts +12 -30
- package/src/organizationsCore.ts +1 -1
- package/src/own.ts +21 -19
- package/src/pages/components/frame.kay +3 -3
- package/src/pages/components/passkey-add.kay +2 -2
- package/src/pages/components/passkey-sign-in.kay +2 -2
- package/src/pages/components/passkey-two-factor.kay +2 -2
- package/src/pages/components/provider-buttons.kay +1 -1
- package/src/pages/forms.ts +6 -6
- package/src/pages/index.ts +9 -8
- package/src/pages/routes/account/clients.kay +2 -2
- package/src/pages/routes/account/connections.kay +4 -4
- package/src/pages/routes/account/data.kay +7 -7
- package/src/pages/routes/account/index.kay +15 -15
- package/src/pages/routes/account/organizations/[org].kay +15 -15
- package/src/pages/routes/account/organizations/index.kay +5 -5
- package/src/pages/routes/account/security.kay +15 -15
- package/src/pages/routes/account/tokens.kay +4 -4
- package/src/pages/routes/admin/_layout.kay +1 -1
- package/src/pages/routes/admin/audit.kay +1 -1
- package/src/pages/routes/admin/users/[id].kay +11 -11
- package/src/pages/routes/confirm-email.kay +3 -3
- package/src/pages/routes/invitation.kay +8 -8
- package/src/pages/routes/magic-link.kay +3 -3
- package/src/pages/routes/oauth/authorize.kay +2 -2
- package/src/pages/routes/register.kay +4 -4
- package/src/pages/routes/reset-password.kay +6 -6
- package/src/pages/routes/sign-in.kay +10 -10
- package/src/pages/routes/two-factor.kay +4 -4
- package/src/pages/routes/verify-email.kay +8 -8
- package/src/passkeys.ts +10 -21
- package/src/password.ts +8 -11
- package/src/pg.ts +3 -3
- package/src/profile.ts +1 -3
- package/src/proof.ts +3 -5
- package/src/request.ts +77 -46
- package/src/requiredTwoFactor.ts +2 -2
- package/src/routes.ts +2 -2
- package/src/sessions.ts +3 -7
- package/src/setup.ts +6 -4
- package/src/sqlite.ts +6 -0
- package/src/test.ts +15 -3
- package/src/testHelpers.ts +16 -7
- package/src/testHook.ts +31 -0
- package/src/testing.ts +5 -4
- package/src/twoFactor.ts +9 -18
- package/src/viewer.ts +26 -4
- package/src/webauthn.ts +2 -2
- package/types/account.d.ts +10 -23
- package/types/account.d.ts.map +1 -1
- package/types/admin.d.ts +21 -39
- package/types/admin.d.ts.map +1 -1
- package/types/auth.d.ts +18 -5
- package/types/auth.d.ts.map +1 -1
- package/types/authorize/grants.d.ts +2 -5
- package/types/authorize/grants.d.ts.map +1 -1
- package/types/authorize/request.d.ts +3 -5
- package/types/authorize/request.d.ts.map +1 -1
- package/types/bearer.d.ts +9 -17
- package/types/bearer.d.ts.map +1 -1
- package/types/captcha.d.ts +3 -1
- package/types/captcha.d.ts.map +1 -1
- package/types/context.d.ts +1 -1
- package/types/deletion.d.ts +2 -5
- package/types/deletion.d.ts.map +1 -1
- package/types/email.d.ts +23 -28
- package/types/email.d.ts.map +1 -1
- package/types/erase.d.ts.map +1 -1
- package/types/export.d.ts +3 -5
- package/types/export.d.ts.map +1 -1
- package/types/failure.d.ts +22 -3
- package/types/failure.d.ts.map +1 -1
- package/types/guard.d.ts +2 -0
- package/types/guard.d.ts.map +1 -1
- package/types/guards.d.ts +2 -1
- package/types/guards.d.ts.map +1 -1
- package/types/index.d.ts +14 -16
- package/types/index.d.ts.map +1 -1
- package/types/limits.d.ts +57 -1
- package/types/limits.d.ts.map +1 -1
- package/types/mail.d.ts +5 -0
- package/types/mail.d.ts.map +1 -1
- package/types/messages/fr.d.ts +1 -0
- package/types/methods/account.d.ts +27 -13
- package/types/methods/account.d.ts.map +1 -1
- package/types/methods/admin.d.ts +39 -15
- package/types/methods/admin.d.ts.map +1 -1
- package/types/methods/captcha.d.ts +9 -0
- package/types/methods/captcha.d.ts.map +1 -0
- package/types/methods/email.d.ts +21 -7
- package/types/methods/email.d.ts.map +1 -1
- package/types/methods/magicLink.d.ts +9 -4
- package/types/methods/magicLink.d.ts.map +1 -1
- package/types/methods/oauth.d.ts +12 -7
- package/types/methods/oauth.d.ts.map +1 -1
- package/types/methods/oauthServer.d.ts +13 -5
- package/types/methods/oauthServer.d.ts.map +1 -1
- package/types/methods/organizations.d.ts +40 -15
- package/types/methods/organizations.d.ts.map +1 -1
- package/types/methods/passkeys.d.ts +18 -7
- package/types/methods/passkeys.d.ts.map +1 -1
- package/types/methods/password.d.ts +23 -10
- package/types/methods/password.d.ts.map +1 -1
- package/types/methods/proof.d.ts +12 -0
- package/types/methods/proof.d.ts.map +1 -0
- package/types/methods/sessions.d.ts +3 -2
- package/types/methods/sessions.d.ts.map +1 -1
- package/types/methods/tokens.d.ts +12 -5
- package/types/methods/tokens.d.ts.map +1 -1
- package/types/methods/twoFactor.d.ts +22 -10
- package/types/methods/twoFactor.d.ts.map +1 -1
- package/types/oauth/flow.d.ts +4 -6
- package/types/oauth/flow.d.ts.map +1 -1
- package/types/oauthTest.d.ts +2 -0
- package/types/oauthTest.d.ts.map +1 -1
- package/types/organizations.d.ts +24 -48
- package/types/organizations.d.ts.map +1 -1
- package/types/own.d.ts +1 -1
- package/types/own.d.ts.map +1 -1
- package/types/pages/forms.d.ts +5 -3
- package/types/pages/forms.d.ts.map +1 -1
- package/types/pages/index.d.ts +5 -2
- package/types/pages/index.d.ts.map +1 -1
- package/types/passkeys.d.ts +20 -27
- package/types/passkeys.d.ts.map +1 -1
- package/types/password.d.ts +13 -20
- package/types/password.d.ts.map +1 -1
- package/types/profile.d.ts +1 -4
- package/types/profile.d.ts.map +1 -1
- package/types/proof.d.ts +1 -4
- package/types/proof.d.ts.map +1 -1
- package/types/request.d.ts +33 -7
- package/types/request.d.ts.map +1 -1
- package/types/requiredTwoFactor.d.ts +3 -1
- package/types/requiredTwoFactor.d.ts.map +1 -1
- package/types/routes.d.ts +3 -1
- package/types/routes.d.ts.map +1 -1
- package/types/sessions.d.ts +3 -10
- package/types/sessions.d.ts.map +1 -1
- package/types/setup.d.ts.map +1 -1
- package/types/sqlite.d.ts +3 -0
- package/types/sqlite.d.ts.map +1 -0
- package/types/test.d.ts +4 -1
- package/types/test.d.ts.map +1 -1
- package/types/testHelpers.d.ts +1 -0
- package/types/testHelpers.d.ts.map +1 -1
- package/types/testHook.d.ts +15 -0
- package/types/testHook.d.ts.map +1 -0
- package/types/testing.d.ts.map +1 -1
- package/types/twoFactor.d.ts +10 -21
- package/types/twoFactor.d.ts.map +1 -1
- package/types/viewer.d.ts +3 -1
- package/types/viewer.d.ts.map +1 -1
package/src/own.ts
CHANGED
|
@@ -7,11 +7,10 @@ import type { ProviderOptions } from './oauth/providers'
|
|
|
7
7
|
import type { AuthPagesConfig, AuthPagesOptions, UserMaker } from './pages'
|
|
8
8
|
import type { AuthStore } from './store'
|
|
9
9
|
import type { OwnTest } from './test'
|
|
10
|
-
import { existsSync } from 'node:fs'
|
|
11
10
|
import { normalize, resolve } from 'node:path'
|
|
12
11
|
import process from 'node:process'
|
|
13
12
|
import { s } from 'kay'
|
|
14
|
-
import { appStore, configError } from 'kay/library'
|
|
13
|
+
import { APP_SQLITE_FILE, appStore, configError, defaultSqliteFile } from 'kay/library'
|
|
15
14
|
import { session } from 'kay/server'
|
|
16
15
|
import { log } from './log'
|
|
17
16
|
import { memoryAuth } from './memoryStore'
|
|
@@ -44,7 +43,7 @@ const PRESETS = {
|
|
|
44
43
|
} as unknown as Record<string, (options: ProviderOptions) => OAuthApp['provider']>
|
|
45
44
|
|
|
46
45
|
/** The hooks an app keeps in `src/auth.ts` as `export const hooks`, or hands to `auth({ hooks })`. */
|
|
47
|
-
export type AuthHooks = Partial<Pick<AuthOptions<AuthSessionData, string>, 'allow' | 'authorize' | 'exportData' | 'locate' | 'onEvent' | 'beforeDelete' | 'onSignUp' | 'profileFields'>>
|
|
46
|
+
export type AuthHooks = Partial<Pick<AuthOptions<AuthSessionData, string>, 'allow' | 'authorize' | 'exportData' | 'locate' | 'onEvent' | 'beforeDelete' | 'afterSignUp' | 'onSignUp' | 'profileFields'>>
|
|
48
47
|
|
|
49
48
|
/** Where kayjs-auth keeps its data when `store` is left out: a pg-orm database at `url`, the database of the app's `store` in kay.config.ts when it names one, else a SQLite file `data/auth.sqlite` (`data/auth.db` where an app already has it). */
|
|
50
49
|
export interface StoreUrl {
|
|
@@ -92,11 +91,11 @@ function isPreset(app: true | PresetApp | OAuthApp): app is true | PresetApp {
|
|
|
92
91
|
export function ownEnv(options: Pick<OwnOptions, 'oauth' | 'store'>) {
|
|
93
92
|
const names = Object.entries(options.oauth ?? {}).filter(([, app]) => isPreset(app) && (app === true || app.clientId === undefined || app.clientSecret === undefined)).map(([name]) => name)
|
|
94
93
|
|
|
95
|
-
return s.
|
|
96
|
-
...options.store === undefined && { AUTH_DATABASE_URL: s.
|
|
94
|
+
return s.object({
|
|
95
|
+
...options.store === undefined && { AUTH_DATABASE_URL: s.string({ optional: true, description: 'the database kayjs-auth keeps its users in, a Postgres or SQLite url; the one of the app\'s store, else data/auth.sqlite (SQLite; data/auth.db where it exists), when unset' }) },
|
|
97
96
|
...Object.fromEntries(names.flatMap(name => [
|
|
98
|
-
[`${name.toUpperCase()}_CLIENT_ID`, s.
|
|
99
|
-
[`${name.toUpperCase()}_CLIENT_SECRET`, s.
|
|
97
|
+
[`${name.toUpperCase()}_CLIENT_ID`, s.string({ description: `the ${name} OAuth app's client id`, requiredInProduction: true })],
|
|
98
|
+
[`${name.toUpperCase()}_CLIENT_SECRET`, s.string({ description: `the ${name} OAuth app's client secret`, requiredInProduction: true })],
|
|
100
99
|
])),
|
|
101
100
|
})
|
|
102
101
|
}
|
|
@@ -155,9 +154,8 @@ function foreignTables(names: readonly string[]): RegExp {
|
|
|
155
154
|
return new RegExp(`^(?!(?:${names.join('|')})$)`)
|
|
156
155
|
}
|
|
157
156
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
const LEGACY_OWN_FILE = 'data/auth.db'
|
|
157
|
+
// The files the users were kept in before every default shared `data/app.sqlite` (`data/auth.db` before 1.88 gave the data files their extension): an app whose users are in one keeps it.
|
|
158
|
+
const LEGACY_OWN_FILES = ['data/auth.db', 'data/auth.sqlite']
|
|
161
159
|
const warned = new Set<string>()
|
|
162
160
|
|
|
163
161
|
async function storeOf(store: StoreOption | undefined, root: string, shared: string | undefined, exporting: boolean | undefined): Promise<AuthStore> {
|
|
@@ -175,9 +173,9 @@ async function storeOf(store: StoreOption | undefined, root: string, shared: str
|
|
|
175
173
|
return memoryAuth()
|
|
176
174
|
|
|
177
175
|
// The database of the app's own `store` when it names one, so `sqliteData` or `pgData(url)` in kay.config.ts is the only place to say where the data lives.
|
|
178
|
-
// An app whose users are already in `data/auth.db` keeps them there, so an upgrade loses no one.
|
|
179
|
-
const file =
|
|
180
|
-
const kept = given === undefined && shared !== undefined &&
|
|
176
|
+
// An app whose users are already in `data/auth.sqlite` or `data/auth.db` keeps them there, so an upgrade loses no one.
|
|
177
|
+
const file = defaultSqliteFile(LEGACY_OWN_FILES, root)
|
|
178
|
+
const kept = given === undefined && shared !== undefined && file !== APP_SQLITE_FILE
|
|
181
179
|
const url = kept ? undefined : given ?? shared
|
|
182
180
|
|
|
183
181
|
if (kept && !warned.has(root)) {
|
|
@@ -196,9 +194,13 @@ async function storeOf(store: StoreOption | undefined, root: string, shared: str
|
|
|
196
194
|
throw configError('auth', 'store', 'the store of auth() is a pg-orm database, and @kaynooo/pg-orm is not installed: install it, or give `store` an AuthStore', { cause: error })
|
|
197
195
|
}
|
|
198
196
|
|
|
199
|
-
const
|
|
197
|
+
const target = underRoot(url ?? `sqlite://${file}`, root)
|
|
198
|
+
const db = new orm.Database({ url: target, tables: [...pg.authTables] })
|
|
200
199
|
|
|
201
|
-
|
|
200
|
+
// The app's database and `data/app.sqlite` hold tables that are not kayjs-auth's, which the sync must leave alone.
|
|
201
|
+
const shares = !kept && ((url !== undefined && shared !== undefined && sameDatabase(url, shared, root)) || sameDatabase(target, `sqlite://${APP_SQLITE_FILE}`, root))
|
|
202
|
+
|
|
203
|
+
await db.sync(shares ? { ignoreTables: [foreignTables(pg.authTables.map(table => table.name))] } : undefined)
|
|
202
204
|
|
|
203
205
|
return pg.pgAuth(db)
|
|
204
206
|
}
|
|
@@ -232,17 +234,17 @@ async function registeredMailer(app: ExtensionApp): Promise<unknown> {
|
|
|
232
234
|
if (!app.extensions.includes(MAIL_EXTENSION))
|
|
233
235
|
return undefined
|
|
234
236
|
|
|
235
|
-
let mail: typeof import('@kayjs/mail')
|
|
237
|
+
let mail: typeof import('@kayjs/mail/internal')
|
|
236
238
|
|
|
237
239
|
try {
|
|
238
|
-
mail = await import('@kayjs/mail')
|
|
240
|
+
mail = await import('@kayjs/mail/internal')
|
|
239
241
|
}
|
|
240
242
|
catch {
|
|
241
243
|
return undefined
|
|
242
244
|
}
|
|
243
245
|
|
|
244
246
|
// A failure of the registered loader is the app's to see.
|
|
245
|
-
return mail.
|
|
247
|
+
return mail.runningMailer()
|
|
246
248
|
}
|
|
247
249
|
|
|
248
250
|
export async function emailOf(email: OwnOptions['email'], app: ExtensionApp): Promise<EmailOptions | undefined> {
|
|
@@ -288,7 +290,7 @@ export async function buildOwn(options: OwnOptions, app: ExtensionApp): Promise<
|
|
|
288
290
|
const mailer = await emailOf(email, app)
|
|
289
291
|
|
|
290
292
|
if (store === undefined && app.database === undefined && process.env.NODE_ENV === 'production' && databaseUrlFromEnv() === undefined) {
|
|
291
|
-
const file =
|
|
293
|
+
const file = defaultSqliteFile(LEGACY_OWN_FILES, app.root)
|
|
292
294
|
|
|
293
295
|
log.warn(appStore()?.sql === undefined
|
|
294
296
|
? `auth() keeps its users in ${file}, a SQLite file: set the app's \`store\` (\`sqliteData\` or \`pgData\`) in kay.config.ts, AUTH_DATABASE_URL, or auth's \`store\`, for a database that outlives a deploy`
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
---
|
|
2
2
|
const { size, gap, landmark = true } = props<{ size: string, gap: string, landmark?: boolean }>()
|
|
3
|
-
const classes = `kayjs-auth mx-auto flex w-full ${size} flex-col ${gap} px-4 py-8`
|
|
3
|
+
const classes = () => `kayjs-auth mx-auto flex w-full ${size} flex-col ${gap} px-4 py-8`
|
|
4
4
|
---
|
|
5
5
|
// A prebuilt page's frame: a `main` landmark unless `pages.main` is false, for an app whose layout writes one.
|
|
6
6
|
if landmark
|
|
7
|
-
main(class={classes})
|
|
7
|
+
main(class={classes()})
|
|
8
8
|
slot
|
|
9
9
|
else
|
|
10
|
-
div(class={classes})
|
|
10
|
+
div(class={classes()})
|
|
11
11
|
slot
|
|
@@ -24,11 +24,11 @@ async function add(event: SubmitEvent) {
|
|
|
24
24
|
|
|
25
25
|
proof.delete('name')
|
|
26
26
|
|
|
27
|
-
const options = await passkeyOptions(proof, { refresh: false })
|
|
27
|
+
const options = await passkeyOptions(proof, { refresh: false }).orThrow()
|
|
28
28
|
const response = await makePasskey(options)
|
|
29
29
|
|
|
30
30
|
if (response)
|
|
31
|
-
await addPasskey({ response, ...(name() ? { name: name() } : {}) })
|
|
31
|
+
await addPasskey({ response, ...(name() ? { name: name() } : {}) }).orThrow()
|
|
32
32
|
}
|
|
33
33
|
catch (caught) {
|
|
34
34
|
error = passkeyFailure(caught, errors, failed)
|
|
@@ -16,12 +16,12 @@ async function signIn() {
|
|
|
16
16
|
error = ''
|
|
17
17
|
|
|
18
18
|
try {
|
|
19
|
-
const options = await passkeyOptions({}, { refresh: false })
|
|
19
|
+
const options = await passkeyOptions({}, { refresh: false }).orThrow()
|
|
20
20
|
const response = await askPasskey(options)
|
|
21
21
|
const remember = rememberChoice()
|
|
22
22
|
|
|
23
23
|
if (response)
|
|
24
|
-
await passkey({ response, redirect, ...(remember === undefined ? {} : { remember }) })
|
|
24
|
+
await passkey({ response, redirect, ...(remember === undefined ? {} : { remember }) }).orThrow()
|
|
25
25
|
}
|
|
26
26
|
catch (caught) {
|
|
27
27
|
error = passkeyFailure(caught, {}, failed)
|
|
@@ -16,11 +16,11 @@ async function verify() {
|
|
|
16
16
|
error = ''
|
|
17
17
|
|
|
18
18
|
try {
|
|
19
|
-
const options = await passkeyOptions({}, { refresh: false })
|
|
19
|
+
const options = await passkeyOptions({}, { refresh: false }).orThrow()
|
|
20
20
|
const response = await askPasskey(options)
|
|
21
21
|
|
|
22
22
|
if (response)
|
|
23
|
-
await passkey({ response })
|
|
23
|
+
await passkey({ response }).orThrow()
|
|
24
24
|
}
|
|
25
25
|
catch (caught) {
|
|
26
26
|
error = passkeyFailure(caught, {}, failed)
|
|
@@ -22,4 +22,4 @@ function carryRemember(event: Event) {
|
|
|
22
22
|
// kay-allow unreachable-click
|
|
23
23
|
.flex.flex-col.gap-2(onClick={carryRemember} onAuxClick={carryRemember})
|
|
24
24
|
for provider of providers key={provider.name}
|
|
25
|
-
Button(href={provider.href} label={provider.label} data-provider={provider.name} data-
|
|
25
|
+
Button(href={provider.href} label={provider.label} data-provider={provider.name} data-prefetch="false")
|
package/src/pages/forms.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { MinTimeRefusal } from 'kay'
|
|
|
2
2
|
import type { Auth } from '../auth'
|
|
3
3
|
import type { CaptchaAction } from '../captcha'
|
|
4
4
|
import type { Proof } from '../proof'
|
|
5
|
-
import type { AuthFeatures
|
|
5
|
+
import type { AuthFeatures } from './index'
|
|
6
6
|
import { t } from 'elysia'
|
|
7
7
|
import { wording } from 'kay/words'
|
|
8
8
|
import { passkeyAssertion, passkeyAttestation } from '../payloads'
|
|
@@ -115,11 +115,11 @@ export function refusedFor<Code extends string>(error: Code, input: Parameters<t
|
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
// Whether the page shows its CAPTCHA for `action`, with the proof of work's challenge, reading the client's attempts once.
|
|
118
|
-
export async function captchaFor(auth: Pick<Auth, '
|
|
118
|
+
export async function captchaFor(auth: { captcha: Pick<Auth['captcha'], 'required' | 'challenge'> }, captcha: AuthFeatures['captcha'], action: CaptchaAction): Promise<{ shown: boolean, challenge: string | null }> {
|
|
119
119
|
if (captcha !== 'proof-of-work')
|
|
120
|
-
return { shown: captcha !== null && await auth.
|
|
120
|
+
return { shown: captcha !== null && await auth.captcha.required(action), challenge: null }
|
|
121
121
|
|
|
122
|
-
const challenge = await auth.
|
|
122
|
+
const challenge = await auth.captcha.challenge(action)
|
|
123
123
|
|
|
124
124
|
return { shown: challenge !== null, challenge }
|
|
125
125
|
}
|
|
@@ -171,8 +171,8 @@ export function issue(...[field, problem, rules]: [field: 'email', problem: Prob
|
|
|
171
171
|
}
|
|
172
172
|
|
|
173
173
|
// What a page shows under a profile field the app asked for, `max` being the field's own limit when it set one.
|
|
174
|
-
export function profileIssue(problem:
|
|
175
|
-
return
|
|
174
|
+
export function profileIssue(problem: string, max?: number): string {
|
|
175
|
+
return problem === 'required' || problem === 'too-long' ? wording(`auth.fields.profile.${problem}`, FIELD_ERRORS.profile[problem], { max: max ?? PROFILE_MAX_LENGTH }) : problem
|
|
176
176
|
}
|
|
177
177
|
|
|
178
178
|
// The message for the `?error=` a failed provider sign-in comes back with; undefined for none, or one kayjs-auth never sends.
|
package/src/pages/index.ts
CHANGED
|
@@ -2,12 +2,13 @@ import type { ExtensionApp, KayExtension, PluginInput } from 'kay/server'
|
|
|
2
2
|
import type { CaptchaWidget } from '../captcha'
|
|
3
3
|
import type { BareUser, Core } from '../core'
|
|
4
4
|
import type { CodedLink, CodeMode } from '../email'
|
|
5
|
+
import type { Result } from '../failure'
|
|
5
6
|
import type { OrganizationsCore } from '../organizationsCore'
|
|
6
7
|
import type { OwnOptions, OwnPlugin } from '../own'
|
|
7
|
-
import type { CreateUserInput,
|
|
8
|
+
import type { CreateUserInput, RegisterErrors } from '../password'
|
|
8
9
|
import type { LinkType } from '../store'
|
|
9
10
|
import { resolve } from 'node:path'
|
|
10
|
-
import { appModules, checkOptionKeys, configError } from 'kay/library'
|
|
11
|
+
import { appModules, checkOptionKeys, configError, KayError } from 'kay/library'
|
|
11
12
|
import { pickLocale } from '../locale'
|
|
12
13
|
import { buildOwn, MAIL_EXTENSION, ownEnv } from '../own'
|
|
13
14
|
|
|
@@ -93,7 +94,7 @@ export interface AuthFeatures {
|
|
|
93
94
|
magicLink: boolean
|
|
94
95
|
// Whether users can turn on two-step verification, `twoFactor: false` switching that off.
|
|
95
96
|
twoFactor: boolean
|
|
96
|
-
// The CAPTCHA widget to show where `
|
|
97
|
+
// The CAPTCHA widget to show where `captcha.required` says one is needed, `'proof-of-work'` for kay's, whose field carries `captcha.challenge`, or null without one.
|
|
97
98
|
captcha: CaptchaWidget | 'proof-of-work' | null
|
|
98
99
|
// What a bearer token may be limited to; any token may do anything without them.
|
|
99
100
|
scopes: string[]
|
|
@@ -205,7 +206,7 @@ export const CHECK_USER = Symbol('kayjs-auth.checkUser')
|
|
|
205
206
|
export interface UserMaker {
|
|
206
207
|
// What `createUser` would refuse the login for, asked before the password is.
|
|
207
208
|
[CHECK_USER]: (input: Omit<CreateUserInput, 'roles'> & { roles?: string[] | undefined }) => Promise<Partial<Record<'email' | 'username' | 'password', string>>>
|
|
208
|
-
admin: { createUser: (input: Omit<CreateUserInput, 'roles'> & { roles?: string[] | undefined }) => Promise<
|
|
209
|
+
admin: { createUser: (input: Omit<CreateUserInput, 'roles'> & { roles?: string[] | undefined }) => Promise<Result<{ user: BareUser }, never, RegisterErrors>> }
|
|
209
210
|
}
|
|
210
211
|
|
|
211
212
|
// The commands both extensions add.
|
|
@@ -254,12 +255,12 @@ export interface AuthExtensionOptions extends AuthPagesOptions {
|
|
|
254
255
|
// The `auth` an app's module exports, for `prepare` to hand it the prefix and home `auth()` was given.
|
|
255
256
|
function authOfExport(exported: unknown, module: string): { [PAGES_OF]?: PagesHandle | undefined } {
|
|
256
257
|
if (typeof exported !== 'object' || exported === null || !('plugin' in exported))
|
|
257
|
-
throw new
|
|
258
|
+
throw new KayError('config-invalid', `kayjs-auth: ${module} exports no \`auth\`: export the \`authCore\` result as \`export const auth = authCore(...)\``)
|
|
258
259
|
|
|
259
260
|
return exported as { [PAGES_OF]?: PagesHandle | undefined }
|
|
260
261
|
}
|
|
261
262
|
|
|
262
|
-
const KNOWN_OPTIONS: Record<keyof OwnOptions | keyof AuthExtensionOptions, true> = { module: true, server: true, prefix: true, pages: true, cookie: true, oauth: true, store: true, email: true, hooks: true, viewer: true, secret: true, site: true, name: true, signInPage: true, failurePage: true, twoFactorPage: true, allow: true, signUp: true, onSignUp: true, user: true, profileFields: true, beforeDelete: true, guests: true, exportData: true, onEvent: true, audit: true, scopes: true, roles: true, organizations: true, admin: true, defaultRoles: true, remember: true, rules: true, sessionsPage: true, securityPage: true, locate: true, rateLimit: true, passkeys: true, password: true, magicLink: true, twoFactor: true, captcha: true, breachedPasswords: true, proxy: true, oauthServer: true, forwardAuth: true, authorize: true, home: true, account: true }
|
|
263
|
+
const KNOWN_OPTIONS: Record<keyof OwnOptions | keyof AuthExtensionOptions, true> = { module: true, server: true, prefix: true, pages: true, cookie: true, oauth: true, store: true, email: true, hooks: true, viewer: true, secret: true, site: true, name: true, signInPage: true, failurePage: true, twoFactorPage: true, allow: true, signUp: true, afterSignUp: true, onSignUp: true, user: true, profileFields: true, beforeDelete: true, guests: true, exportData: true, onEvent: true, audit: true, scopes: true, roles: true, organizations: true, admin: true, defaultRoles: true, remember: true, rules: true, sessionsPage: true, securityPage: true, locate: true, rateLimit: true, passkeys: true, password: true, magicLink: true, twoFactor: true, captcha: true, breachedPasswords: true, proxy: true, oauthServer: true, forwardAuth: true, authorize: true, home: true, account: true }
|
|
263
264
|
|
|
264
265
|
// kayjs-auth for `extensions` in kay.config.ts, as the whole declaration: `auth({ module: './src/auth' })`, the module exporting the `auth` made with `authCore`. Its plugin is used before the pages, so the app mounts nothing else and declares no `Register`, and `prefix` and `home` reach `authCore({ pages: true })`; the prebuilt pages come with it unless `pages: false`.
|
|
265
266
|
export function auth<Role extends string = string, Prefix extends string = '/auth', const Scope extends string = never, OrgRole extends string = never, UserData extends object = Record<string, never>>(options?: OwnOptions<Role, Prefix, Scope, OrgRole, UserData>): AuthPages<OwnPlugin<Role, Prefix, Scope, OrgRole, UserData>>
|
|
@@ -309,7 +310,7 @@ function moduleAuth(options: AuthExtensionOptions): AuthPages {
|
|
|
309
310
|
const server = options.server === false ? undefined : options.server
|
|
310
311
|
|
|
311
312
|
if (module !== undefined && options.server !== undefined)
|
|
312
|
-
throw new
|
|
313
|
+
throw new KayError('config-invalid', 'kayjs-auth: auth() takes `module` or `server`, not both')
|
|
313
314
|
|
|
314
315
|
const given = { prefix: options.prefix, home }
|
|
315
316
|
const extension: AuthPages = {
|
|
@@ -355,7 +356,7 @@ export function profileValue(name: string, held: unknown): string {
|
|
|
355
356
|
return ''
|
|
356
357
|
|
|
357
358
|
if (typeof held !== 'string')
|
|
358
|
-
throw new
|
|
359
|
+
throw new KayError('argument-invalid', `kayjs-auth: pages.profile.load answered a ${typeof held} for the field "${name}", which takes a string, null or undefined`)
|
|
359
360
|
|
|
360
361
|
return held
|
|
361
362
|
}
|
|
@@ -9,10 +9,10 @@ import EmptyState from '@kayjs/ui/empty-state.kay'
|
|
|
9
9
|
import PageSection from '@kayjs/ui/page-section.kay'
|
|
10
10
|
|
|
11
11
|
export const revoke = action(schemas.oauthClient, async ({ id }, ctx) => {
|
|
12
|
-
return (await ctx.locals.auth.oauthServer.revokeGrant(id)).ok ? 'revoked' : ctx.
|
|
12
|
+
return (await ctx.locals.auth.oauthServer.revokeGrant(id)).ok ? 'revoked' : ctx.deny(404, { data: { error: 'not-found' } })
|
|
13
13
|
})
|
|
14
14
|
|
|
15
|
-
const clients = await ctx.locals.auth.oauthServer.
|
|
15
|
+
const clients = await ctx.locals.auth.oauthServer.listClients()
|
|
16
16
|
const date = (value: Date) => formatDate(value, { dateStyle: 'medium' })
|
|
17
17
|
---
|
|
18
18
|
PageSection(title={wording('auth.account.clients.title', 'Connected apps')})
|
|
@@ -16,20 +16,20 @@ export const connect = action(schemas.unlink, async (input, ctx) => {
|
|
|
16
16
|
const features = auth.features()
|
|
17
17
|
const started = await auth.oauth.link(input.provider, proofOf(input), { redirect: localize(`${features.pages?.prefix ?? features.prefix}/account/connections`) })
|
|
18
18
|
|
|
19
|
-
return started.ok ? ctx.redirect(started.url) : ctx.
|
|
19
|
+
return started.ok ? ctx.redirect(started.url) : ctx.deny(400, { data: { error: started.error.code, provider: input.provider } })
|
|
20
20
|
})
|
|
21
21
|
|
|
22
22
|
export const disconnect = action(schemas.unlink, async (input, ctx) => {
|
|
23
23
|
const result = await ctx.locals.auth.oauth.unlink(input.provider, proofOf(input))
|
|
24
24
|
|
|
25
|
-
return result.ok ? 'disconnected' : ctx.
|
|
25
|
+
return result.ok ? 'disconnected' : ctx.deny(400, { data: { error: result.error.code, provider: input.provider } })
|
|
26
26
|
})
|
|
27
27
|
|
|
28
28
|
const auth = ctx.locals.auth
|
|
29
29
|
const user = await auth.requireUser()
|
|
30
30
|
const features = auth.features()
|
|
31
|
-
const linked = new Set(await auth.oauth.
|
|
32
|
-
const refused = connect.failed()?.data ?? disconnect.failed()?.data
|
|
31
|
+
const linked = new Set(await auth.oauth.listIdentities())
|
|
32
|
+
const refused = connect.form.failed()?.data ?? disconnect.form.failed()?.data
|
|
33
33
|
---
|
|
34
34
|
PageSection(title={wording('auth.account.connections.title', 'Connected accounts')})
|
|
35
35
|
.flex.flex-col.gap-2
|
|
@@ -11,16 +11,16 @@ import PageSection from '@kayjs/ui/page-section.kay'
|
|
|
11
11
|
|
|
12
12
|
// Re-proves the user, so the export link below shows for the next ten minutes.
|
|
13
13
|
export const prove = action(schemas.proof, async (input, ctx) => {
|
|
14
|
-
const result = await ctx.locals.auth.
|
|
14
|
+
const result = await ctx.locals.auth.proof.renew(proofOf(input))
|
|
15
15
|
|
|
16
|
-
return !result.ok ? ctx.
|
|
16
|
+
return !result.ok ? ctx.deny(400, { data: { error: result.error.code } }) : undefined
|
|
17
17
|
})
|
|
18
18
|
|
|
19
19
|
export const remove = action(schemas.proof, async (input, ctx) => {
|
|
20
20
|
const result = await ctx.locals.auth.account.delete(proofOf(input))
|
|
21
21
|
|
|
22
22
|
if (!result.ok)
|
|
23
|
-
return ctx.
|
|
23
|
+
return ctx.deny(400, { data: { error: result.error.code } })
|
|
24
24
|
|
|
25
25
|
const { pages, prefix } = ctx.locals.auth.features()
|
|
26
26
|
|
|
@@ -49,9 +49,9 @@ export const signInAgain = action(async (ctx) => {
|
|
|
49
49
|
const auth = ctx.locals.auth
|
|
50
50
|
const user = await auth.requireUser()
|
|
51
51
|
const features = auth.features()
|
|
52
|
-
const refused = remove.failed()?.data?.error
|
|
53
|
-
const notProved = prove.failed()?.data?.error
|
|
54
|
-
const proved = await auth.
|
|
52
|
+
const refused = remove.form.failed()?.data?.error
|
|
53
|
+
const notProved = prove.form.failed()?.data?.error
|
|
54
|
+
const proved = await auth.proof.recent()
|
|
55
55
|
// Neither proof form can pass: an admin acting as the user proves nothing, and an account with nothing to prove it by has only its sign-in, now old.
|
|
56
56
|
const impersonated = await auth.impersonator() !== null
|
|
57
57
|
const impact = await auth.account.deletionImpact()
|
|
@@ -68,7 +68,7 @@ else
|
|
|
68
68
|
.flex.flex-col.items-start.gap-3
|
|
69
69
|
p {wording('auth.account.data.exportIntro', 'Everything we keep about your account, as a JSON file.')}
|
|
70
70
|
if proved
|
|
71
|
-
Button(href={`${features.prefix}/export`} label={wording('auth.account.data.export', 'Download your data')} download data-
|
|
71
|
+
Button(href={`${features.prefix}/export`} label={wording('auth.account.data.export', 'Download your data')} download data-prefetch="false")
|
|
72
72
|
else if stale
|
|
73
73
|
form.flex.flex-col.items-start.gap-3(action={signInAgain})
|
|
74
74
|
p {wording('auth.proof.stale', 'For your safety, sign in again before doing this.')}
|
|
@@ -12,32 +12,32 @@ import PageSection from '@kayjs/ui/page-section.kay'
|
|
|
12
12
|
export const resend = action(async (ctx) => {
|
|
13
13
|
const result = await ctx.locals.auth.email.sendVerification()
|
|
14
14
|
|
|
15
|
-
return result.ok ? 'sent' : ctx.
|
|
15
|
+
return result.ok ? 'sent' : ctx.deny(400, { data: { error: result.error.code } })
|
|
16
16
|
})
|
|
17
17
|
|
|
18
18
|
export const changeEmail = action(schemas.changeEmail, async (input, ctx) => {
|
|
19
19
|
const result = await ctx.locals.auth.email.change(proofOf(input), input.email)
|
|
20
20
|
|
|
21
21
|
if (!result.ok)
|
|
22
|
-
return ctx.
|
|
22
|
+
return ctx.deny(400, { data: 'errors' in result ? { email: result.errors.email } : { error: result.error.code } })
|
|
23
23
|
|
|
24
24
|
return input.email
|
|
25
25
|
})
|
|
26
26
|
|
|
27
27
|
export const changeUsername = action(schemas.changeUsername, async ({ username }, ctx) => {
|
|
28
|
-
const result = await ctx.locals.auth.account.
|
|
28
|
+
const result = await ctx.locals.auth.account.updateUsername(username)
|
|
29
29
|
|
|
30
30
|
if (!result.ok)
|
|
31
|
-
return ctx.
|
|
31
|
+
return ctx.deny(400, { data: 'errors' in result ? { username: result.errors.username } : { error: result.error.code } })
|
|
32
32
|
|
|
33
33
|
return 'saved'
|
|
34
34
|
})
|
|
35
35
|
|
|
36
36
|
export const saveProfile = action(schemas.profile, async (input, ctx) => {
|
|
37
|
-
const result = await ctx.locals.auth.account.
|
|
37
|
+
const result = await ctx.locals.auth.account.updateProfile(input)
|
|
38
38
|
|
|
39
39
|
if (!result.ok)
|
|
40
|
-
return ctx.
|
|
40
|
+
return ctx.deny(400, { data: 'errors' in result ? { errors: result.errors } : { error: 'form' as const } })
|
|
41
41
|
|
|
42
42
|
return 'saved'
|
|
43
43
|
})
|
|
@@ -45,15 +45,15 @@ export const saveProfile = action(schemas.profile, async (input, ctx) => {
|
|
|
45
45
|
const auth = ctx.locals.auth
|
|
46
46
|
const user = await auth.requireUser()
|
|
47
47
|
const features = auth.features()
|
|
48
|
-
const resent = resend.
|
|
49
|
-
const resendError = resend.failed()?.data?.error
|
|
50
|
-
const emailSent = changeEmail.
|
|
51
|
-
const emailRefused = changeEmail.failed()?.data
|
|
52
|
-
const usernameSaved = changeUsername.
|
|
53
|
-
const usernameRefused = changeUsername.failed()?.data
|
|
54
|
-
const profile = await auth.account.
|
|
55
|
-
const profileSaved = saveProfile.
|
|
56
|
-
const profileRefused = saveProfile.failed()?.data
|
|
48
|
+
const resent = resend.status() === 'ready'
|
|
49
|
+
const resendError = resend.form.failed()?.data?.error
|
|
50
|
+
const emailSent = changeEmail.data()
|
|
51
|
+
const emailRefused = changeEmail.form.failed()?.data
|
|
52
|
+
const usernameSaved = changeUsername.status() === 'ready'
|
|
53
|
+
const usernameRefused = changeUsername.form.failed()?.data
|
|
54
|
+
const profile = await auth.account.getProfile(ctx.locale)
|
|
55
|
+
const profileSaved = saveProfile.status() === 'ready'
|
|
56
|
+
const profileRefused = saveProfile.form.failed()?.data
|
|
57
57
|
const profileProblems = profileRefused && 'errors' in profileRefused ? profileRefused.errors : {}
|
|
58
58
|
const problemOf = (name: string) => Object.hasOwn(profileProblems, name) ? profileProblems[name] : undefined
|
|
59
59
|
---
|
|
@@ -18,7 +18,7 @@ export const rename = action(schemas.organization, async ({ name, slug }, ctx) =
|
|
|
18
18
|
const result = await auth.organizations.update(String(ctx.params.org), { name: name.trim(), slug: slug?.trim() || null })
|
|
19
19
|
|
|
20
20
|
if (!result.ok)
|
|
21
|
-
return ctx.
|
|
21
|
+
return ctx.deny(400, { data: { error: result.error.code } })
|
|
22
22
|
|
|
23
23
|
const { organization } = result
|
|
24
24
|
|
|
@@ -26,47 +26,47 @@ export const rename = action(schemas.organization, async ({ name, slug }, ctx) =
|
|
|
26
26
|
})
|
|
27
27
|
|
|
28
28
|
export const setRoles = action(schemas.memberRoles, async ({ userId, roles }, ctx) => {
|
|
29
|
-
const result = await ctx.locals.auth.organizations.
|
|
29
|
+
const result = await ctx.locals.auth.organizations.updateMemberRoles(String(ctx.params.org), userId, (roles ?? []) as never[])
|
|
30
30
|
|
|
31
|
-
return result.ok ? 'done' : ctx.
|
|
31
|
+
return result.ok ? 'done' : ctx.deny(400, { data: { error: result.error.code } })
|
|
32
32
|
})
|
|
33
33
|
|
|
34
34
|
export const removeMember = action(schemas.member, async ({ userId }, ctx) => {
|
|
35
|
-
const result = await ctx.locals.auth.organizations.
|
|
35
|
+
const result = await ctx.locals.auth.organizations.deleteMember(String(ctx.params.org), userId)
|
|
36
36
|
|
|
37
|
-
return result.ok ? 'done' : ctx.
|
|
37
|
+
return result.ok ? 'done' : ctx.deny(400, { data: { error: result.error.code } })
|
|
38
38
|
})
|
|
39
39
|
|
|
40
40
|
export const invite = action(schemas.invite, async ({ email, roles }, ctx) => {
|
|
41
41
|
const result = await ctx.locals.auth.organizations.invite(String(ctx.params.org), email.trim(), roles?.length ? roles as never[] : undefined)
|
|
42
42
|
|
|
43
|
-
return result.ok ? result.invitation.email : ctx.
|
|
43
|
+
return result.ok ? result.invitation.email : ctx.deny(400, { data: { error: result.error.code } })
|
|
44
44
|
})
|
|
45
45
|
|
|
46
46
|
export const revoke = action(schemas.id, async ({ id }, ctx) => {
|
|
47
47
|
const result = await ctx.locals.auth.organizations.revokeInvitation(String(ctx.params.org), id)
|
|
48
48
|
|
|
49
|
-
return result.ok ? 'done' : ctx.
|
|
49
|
+
return result.ok ? 'done' : ctx.deny(400, { data: { error: result.error.code } })
|
|
50
50
|
})
|
|
51
51
|
|
|
52
52
|
export const leave = action(schemas.adminDelete, async ({ confirm }, ctx) => {
|
|
53
53
|
if (confirm !== true)
|
|
54
|
-
return ctx.
|
|
54
|
+
return ctx.deny(400, { data: { error: 'form' } })
|
|
55
55
|
|
|
56
56
|
const auth = ctx.locals.auth
|
|
57
57
|
const result = await auth.organizations.leave(String(ctx.params.org))
|
|
58
58
|
|
|
59
|
-
return result.ok ? ctx.redirect(organizationsPage(auth.features())) : ctx.
|
|
59
|
+
return result.ok ? ctx.redirect(organizationsPage(auth.features())) : ctx.deny(400, { data: { error: result.error.code } })
|
|
60
60
|
})
|
|
61
61
|
|
|
62
62
|
export const remove = action(schemas.adminDelete, async ({ confirm }, ctx) => {
|
|
63
63
|
if (confirm !== true)
|
|
64
|
-
return ctx.
|
|
64
|
+
return ctx.deny(400, { data: { error: 'form' } })
|
|
65
65
|
|
|
66
66
|
const auth = ctx.locals.auth
|
|
67
67
|
const result = await auth.organizations.delete(String(ctx.params.org))
|
|
68
68
|
|
|
69
|
-
return result.ok ? ctx.redirect(organizationsPage(auth.features())) : ctx.
|
|
69
|
+
return result.ok ? ctx.redirect(organizationsPage(auth.features())) : ctx.deny(400, { data: { error: result.error.code } })
|
|
70
70
|
})
|
|
71
71
|
|
|
72
72
|
const auth = ctx.locals.auth
|
|
@@ -84,15 +84,15 @@ const held = new Set(found.roles.flatMap(role => settings.grants[role] ?? []))
|
|
|
84
84
|
|
|
85
85
|
const manages = held.has(settings.manage)
|
|
86
86
|
const owns = held.has(settings.owner)
|
|
87
|
-
const members = await auth.organizations.
|
|
87
|
+
const members = await auth.organizations.listMembers(organization.id)
|
|
88
88
|
const people = members.ok ? members.members : []
|
|
89
|
-
const open = manages ? await auth.organizations.
|
|
89
|
+
const open = manages ? await auth.organizations.listInvitations(organization.id) : null
|
|
90
90
|
const invitations = open?.ok ? open.invitations : []
|
|
91
91
|
// A manager changes only members holding no role above theirs, and gives only roles they hold.
|
|
92
92
|
const editable = (roles: string[]) => manages && roles.every(role => held.has(role))
|
|
93
93
|
const grantable = settings.roles.filter(role => held.has(role))
|
|
94
|
-
const refused = [rename, setRoles, removeMember, invite, revoke, leave, remove].map(
|
|
95
|
-
const invited = invite.
|
|
94
|
+
const refused = [rename, setRoles, removeMember, invite, revoke, leave, remove].map(action => action.form.failed()?.data?.error).find(error => error !== undefined)
|
|
95
|
+
const invited = invite.data()
|
|
96
96
|
const date = (value: Date) => formatDate(value, { dateStyle: 'medium' })
|
|
97
97
|
const label = (user: { email: string | null, username: string | null, id: string }) => user.username ?? user.email ?? user.id
|
|
98
98
|
---
|
|
@@ -16,7 +16,7 @@ export const create = action(schemas.organization, async ({ name, slug }, ctx) =
|
|
|
16
16
|
const result = await ctx.locals.auth.organizations.create({ name: name.trim(), ...slug?.trim() && { slug: slug.trim() } })
|
|
17
17
|
|
|
18
18
|
if (!result.ok)
|
|
19
|
-
return ctx.
|
|
19
|
+
return ctx.deny(400, { data: { error: result.error.code } })
|
|
20
20
|
|
|
21
21
|
const { organization } = result.membership
|
|
22
22
|
|
|
@@ -28,7 +28,7 @@ export const accept = action(schemas.id, async ({ id }, ctx) => {
|
|
|
28
28
|
const result = await ctx.locals.auth.organizations.acceptInvitation(id)
|
|
29
29
|
|
|
30
30
|
if (!result.ok)
|
|
31
|
-
return ctx.
|
|
31
|
+
return ctx.deny(400, { data: { error: result.error.code } })
|
|
32
32
|
|
|
33
33
|
const { organization } = result.membership
|
|
34
34
|
|
|
@@ -38,13 +38,13 @@ export const accept = action(schemas.id, async ({ id }, ctx) => {
|
|
|
38
38
|
export const reject = action(schemas.id, async ({ id }, ctx) => {
|
|
39
39
|
const result = await ctx.locals.auth.organizations.rejectInvitation(id)
|
|
40
40
|
|
|
41
|
-
return result.ok ? 'rejected' : ctx.
|
|
41
|
+
return result.ok ? 'rejected' : ctx.deny(400, { data: { error: result.error.code } })
|
|
42
42
|
})
|
|
43
43
|
|
|
44
44
|
const auth = ctx.locals.auth
|
|
45
45
|
const features = auth.features()
|
|
46
|
-
const [memberships, invitations] = await Promise.all([auth.organizations.list(), auth.organizations.
|
|
47
|
-
const refused = [create, accept, reject].map(
|
|
46
|
+
const [memberships, invitations] = await Promise.all([auth.organizations.list(), auth.organizations.listMyInvitations()])
|
|
47
|
+
const refused = [create, accept, reject].map(action => action.form.failed()?.data?.error).find(error => error !== undefined)
|
|
48
48
|
const date = (value: Date) => formatDate(value, { dateStyle: 'medium' })
|
|
49
49
|
---
|
|
50
50
|
PageSection(title={wording('auth.organizations.title', 'Organizations')})
|