cauthy-auth 0.5.2 → 0.9.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/README.md +68 -3
- package/dist/{cauthy-BCTCqubt.d.ts → cauthy-Bn3iv50y.d.ts} +1 -1
- package/dist/{cauthy-hswMoS7B.d.mts → cauthy-C29HCvag.d.mts} +1 -1
- package/dist/cli.js +490 -25
- package/dist/client.d.mts +273 -0
- package/dist/client.d.ts +273 -0
- package/dist/client.js +342 -0
- package/dist/client.js.map +1 -0
- package/dist/client.mjs +308 -0
- package/dist/client.mjs.map +1 -0
- package/dist/express.d.mts +24 -0
- package/dist/express.d.ts +24 -0
- package/dist/express.js +102 -0
- package/dist/express.js.map +1 -0
- package/dist/express.mjs +76 -0
- package/dist/express.mjs.map +1 -0
- package/dist/fastify.d.mts +2 -2
- package/dist/fastify.d.ts +2 -2
- package/dist/fastify.js +3 -1
- package/dist/fastify.js.map +1 -1
- package/dist/fastify.mjs +3 -1
- package/dist/fastify.mjs.map +1 -1
- package/dist/hono.d.mts +23 -0
- package/dist/hono.d.ts +23 -0
- package/dist/hono.js +50 -0
- package/dist/hono.js.map +1 -0
- package/dist/hono.mjs +24 -0
- package/dist/hono.mjs.map +1 -0
- package/dist/index.d.mts +44 -6
- package/dist/index.d.ts +44 -6
- package/dist/index.js +713 -37
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +701 -37
- package/dist/index.mjs.map +1 -1
- package/dist/next.d.mts +24 -0
- package/dist/next.d.ts +24 -0
- package/dist/next.js +77 -0
- package/dist/next.js.map +1 -0
- package/dist/next.mjs +52 -0
- package/dist/next.mjs.map +1 -0
- package/dist/react.d.mts +592 -7
- package/dist/react.d.ts +592 -7
- package/dist/react.js +1025 -14
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +1013 -10
- package/dist/react.mjs.map +1 -1
- package/dist/styles.css +271 -0
- package/dist/svelte.d.mts +26 -0
- package/dist/svelte.d.ts +26 -0
- package/dist/svelte.js +413 -0
- package/dist/svelte.js.map +1 -0
- package/dist/svelte.mjs +384 -0
- package/dist/svelte.mjs.map +1 -0
- package/dist/{system-DvcQjORr.d.ts → system-DhRr_WxR.d.ts} +139 -1
- package/dist/{system-CR8p4BjB.d.mts → system-ZD_Wa8Bm.d.mts} +139 -1
- package/dist/theme.d.mts +56 -1
- package/dist/theme.d.ts +56 -1
- package/dist/theme.js +181 -5
- package/dist/theme.js.map +1 -1
- package/dist/theme.mjs +176 -4
- package/dist/theme.mjs.map +1 -1
- package/dist/validate-B_iC-4y8.d.mts +19 -0
- package/dist/validate-B_iC-4y8.d.ts +19 -0
- package/dist/vue.d.mts +28 -0
- package/dist/vue.d.ts +28 -0
- package/dist/vue.js +431 -0
- package/dist/vue.js.map +1 -0
- package/dist/vue.mjs +402 -0
- package/dist/vue.mjs.map +1 -0
- package/package.json +68 -7
- package/dist/permissions-B-a3eN0h.d.mts +0 -52
- package/dist/permissions-B-a3eN0h.d.ts +0 -52
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import { CauthyTheme } from './theme.mjs';
|
|
2
|
+
import { i as PublicSession } from './system-ZD_Wa8Bm.mjs';
|
|
3
|
+
import { A as AuthField } from './validate-B_iC-4y8.mjs';
|
|
4
|
+
export { F as FieldProblem, M as MIN_PASSWORD, c as checkCode, a as checkEmail, b as checkName, d as checkNewPassword, e as checkPassword } from './validate-B_iC-4y8.mjs';
|
|
5
|
+
import 'jose';
|
|
6
|
+
|
|
7
|
+
interface SessionState {
|
|
8
|
+
/** The signed-in person and their organizations, or null. */
|
|
9
|
+
session: PublicSession | null;
|
|
10
|
+
status: 'loading' | 'authenticated' | 'unauthenticated';
|
|
11
|
+
}
|
|
12
|
+
interface SessionStoreOptions extends AuthClientOptions {
|
|
13
|
+
/**
|
|
14
|
+
* The session the server already read while rendering (SSR): the first
|
|
15
|
+
* paint is then right, with no "loading". `null` means "nobody"; leave it
|
|
16
|
+
* out when the server did not look.
|
|
17
|
+
*/
|
|
18
|
+
initialSession?: PublicSession | null;
|
|
19
|
+
}
|
|
20
|
+
interface SessionStore {
|
|
21
|
+
/** What is known now. */
|
|
22
|
+
get(): SessionState;
|
|
23
|
+
/** Calls `listener` now and on every change. Answers how to stop. */
|
|
24
|
+
subscribe(listener: (state: SessionState) => void): () => void;
|
|
25
|
+
/** Asks the server again who is signed in. */
|
|
26
|
+
refresh(): Promise<PublicSession | null>;
|
|
27
|
+
/** Sends the browser to Cauthy's page to sign in, and back to `returnTo` (default: where it is now). */
|
|
28
|
+
signIn(options?: {
|
|
29
|
+
returnTo?: string;
|
|
30
|
+
locale?: string;
|
|
31
|
+
prompt?: 'login';
|
|
32
|
+
}): void;
|
|
33
|
+
/** Signs out of this application and of Cauthy in this browser. */
|
|
34
|
+
signOut(): void;
|
|
35
|
+
/** Where the person looks after their account on Cauthy's page. */
|
|
36
|
+
accountUrl(returnTo?: string): string;
|
|
37
|
+
/**
|
|
38
|
+
* The functions of an application's own screens. They are
|
|
39
|
+
* `createAuthClient()`'s, and what changes who is signed in is heard by the
|
|
40
|
+
* subscribers with no reload.
|
|
41
|
+
*/
|
|
42
|
+
auth: AuthClient;
|
|
43
|
+
/** Where the server mounted the routes. */
|
|
44
|
+
basePath: string;
|
|
45
|
+
}
|
|
46
|
+
declare function createSessionStore(options?: SessionStoreOptions): SessionStore;
|
|
47
|
+
|
|
48
|
+
/** What went wrong, in a form the screen can show. */
|
|
49
|
+
interface AuthError {
|
|
50
|
+
/** Stable, for translating: `invalid_credentials`, `invalid_email`, `too_short`, `email_taken`, `unavailable`… */
|
|
51
|
+
code: string;
|
|
52
|
+
message: string;
|
|
53
|
+
/** The input it is about, when it is about one. */
|
|
54
|
+
field?: AuthField;
|
|
55
|
+
}
|
|
56
|
+
type AuthResult<S extends string, More = unknown> = ({
|
|
57
|
+
ok: true;
|
|
58
|
+
status: S;
|
|
59
|
+
} & More) | {
|
|
60
|
+
ok: false;
|
|
61
|
+
error: AuthError;
|
|
62
|
+
};
|
|
63
|
+
/** What the screen may offer. */
|
|
64
|
+
interface AuthMethods {
|
|
65
|
+
/** The providers the workspace signs people in with: `{ id: 'google', name: 'Google' }`. */
|
|
66
|
+
providers: {
|
|
67
|
+
id: string;
|
|
68
|
+
name: string;
|
|
69
|
+
}[];
|
|
70
|
+
/** Whether people may create an account themselves. */
|
|
71
|
+
signUp: boolean;
|
|
72
|
+
magicLink: boolean;
|
|
73
|
+
/** Whether to offer a passkey. It is asked for on Cauthy's page: the person goes there for that step and comes back signed in. */
|
|
74
|
+
passkey: boolean;
|
|
75
|
+
}
|
|
76
|
+
/** A person's own account, as their account screen shows it. */
|
|
77
|
+
interface Account {
|
|
78
|
+
id: string;
|
|
79
|
+
email: string;
|
|
80
|
+
name: string;
|
|
81
|
+
emailVerified: boolean;
|
|
82
|
+
/** False for an account that only signs in through a provider: it has no current password to ask for. */
|
|
83
|
+
hasPassword: boolean;
|
|
84
|
+
mfaEnabled: boolean;
|
|
85
|
+
}
|
|
86
|
+
/** Somewhere the person is signed in. Moments are UTC. */
|
|
87
|
+
interface AccountSession {
|
|
88
|
+
/** "Mac · Chrome", or "" when the browser did not say. */
|
|
89
|
+
device: string;
|
|
90
|
+
ip: string;
|
|
91
|
+
createdAt: string;
|
|
92
|
+
expiresAt: string;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* The signed-in person's own account. What weakens it — the password, the
|
|
96
|
+
* second step, its recovery codes — asks for the current password again.
|
|
97
|
+
*/
|
|
98
|
+
/** A provider the account can also sign in with. */
|
|
99
|
+
interface LinkedIdentity {
|
|
100
|
+
provider: string;
|
|
101
|
+
/** The address the provider has for the person, when it said. */
|
|
102
|
+
email: string;
|
|
103
|
+
name: string;
|
|
104
|
+
/** When it was linked, in UTC (ISO 8601). */
|
|
105
|
+
linkedAt: string;
|
|
106
|
+
}
|
|
107
|
+
interface AccountClient {
|
|
108
|
+
/** The account, or null when nobody is signed in. */
|
|
109
|
+
get(): Promise<Account | null>;
|
|
110
|
+
update(form: {
|
|
111
|
+
name: string;
|
|
112
|
+
}): Promise<AuthResult<'saved', {
|
|
113
|
+
account: Account;
|
|
114
|
+
}>>;
|
|
115
|
+
/** Ends every other session of the account; this one stays signed in. */
|
|
116
|
+
changePassword(form: {
|
|
117
|
+
password: string;
|
|
118
|
+
newPassword: string;
|
|
119
|
+
}): Promise<AuthResult<'changed', {
|
|
120
|
+
signedIn: boolean;
|
|
121
|
+
}>>;
|
|
122
|
+
mfa: {
|
|
123
|
+
/** Starts turning the second step on: show `secret` (or `otpauthUri` as a QR code) to add to an authenticator app, then call `verify`. */
|
|
124
|
+
setup(form: {
|
|
125
|
+
password: string;
|
|
126
|
+
}): Promise<AuthResult<'started', {
|
|
127
|
+
secret: string;
|
|
128
|
+
otpauthUri: string;
|
|
129
|
+
}>>;
|
|
130
|
+
/** Turns it on with a code from the app. `recoveryCodes` are shown this once. */
|
|
131
|
+
verify(form: {
|
|
132
|
+
code: string;
|
|
133
|
+
}): Promise<AuthResult<'enabled', {
|
|
134
|
+
recoveryCodes: string[];
|
|
135
|
+
}>>;
|
|
136
|
+
disable(form: {
|
|
137
|
+
password: string;
|
|
138
|
+
}): Promise<AuthResult<'disabled'>>;
|
|
139
|
+
/** New recovery codes; the earlier ones stop working. */
|
|
140
|
+
recoveryCodes(form: {
|
|
141
|
+
password: string;
|
|
142
|
+
}): Promise<AuthResult<'renewed', {
|
|
143
|
+
recoveryCodes: string[];
|
|
144
|
+
}>>;
|
|
145
|
+
};
|
|
146
|
+
/**
|
|
147
|
+
* Asks to sign in with another address. Nothing changes yet: the new address
|
|
148
|
+
* is mailed a link to confirm it, and once it is confirmed the old one is
|
|
149
|
+
* told, with a link that undoes it. Both open Cauthy's own page.
|
|
150
|
+
*/
|
|
151
|
+
changeEmail(form: {
|
|
152
|
+
email: string;
|
|
153
|
+
password: string;
|
|
154
|
+
}): Promise<AuthResult<'sent', {
|
|
155
|
+
email: string;
|
|
156
|
+
}>>;
|
|
157
|
+
/** The providers (Google…) the account can also sign in with. */
|
|
158
|
+
identities(): Promise<LinkedIdentity[]>;
|
|
159
|
+
/**
|
|
160
|
+
* Sends the browser to the provider, to link it to the account; it comes back
|
|
161
|
+
* at `returnTo` with `?linked=<provider>`, or `?auth_error=<code>`.
|
|
162
|
+
*/
|
|
163
|
+
link(provider: string, options?: {
|
|
164
|
+
returnTo?: string;
|
|
165
|
+
}): void;
|
|
166
|
+
/** Where `link` sends the browser, for a plain link. */
|
|
167
|
+
linkUrl(provider: string, options?: {
|
|
168
|
+
returnTo?: string;
|
|
169
|
+
}): string;
|
|
170
|
+
/** The account stops signing in with that provider. Refused when it would be left with no way to sign in. */
|
|
171
|
+
unlink(provider: string): Promise<AuthResult<'unlinked', {
|
|
172
|
+
provider: string;
|
|
173
|
+
}>>;
|
|
174
|
+
/** Where the account is signed in. */
|
|
175
|
+
sessions(): Promise<AccountSession[]>;
|
|
176
|
+
/** Signs the account out everywhere, here too. */
|
|
177
|
+
signOutEverywhere(): Promise<AuthResult<'signed_out'>>;
|
|
178
|
+
}
|
|
179
|
+
interface AuthClient {
|
|
180
|
+
signIn: {
|
|
181
|
+
/** With address and password. `mfa_required`: ask for the code and call `signIn.mfa`. */
|
|
182
|
+
email(form: {
|
|
183
|
+
email: string;
|
|
184
|
+
password: string;
|
|
185
|
+
}): Promise<AuthResult<'signed_in', {
|
|
186
|
+
session: PublicSession;
|
|
187
|
+
}> | AuthResult<'mfa_required'>>;
|
|
188
|
+
/** The second step: the code of the authenticator app, or a recovery code. */
|
|
189
|
+
mfa(form: {
|
|
190
|
+
code: string;
|
|
191
|
+
}): Promise<AuthResult<'signed_in', {
|
|
192
|
+
session: PublicSession;
|
|
193
|
+
}>>;
|
|
194
|
+
/** Mails a link that signs the person in. The answer is the same whether or not the address has an account. */
|
|
195
|
+
magicLink(form: {
|
|
196
|
+
email: string;
|
|
197
|
+
}): Promise<AuthResult<'sent'>>;
|
|
198
|
+
/** Signs in with the token the mailed link opened the page with (`ml_token`). */
|
|
199
|
+
magicLinkVerify(form: {
|
|
200
|
+
token: string;
|
|
201
|
+
}): Promise<AuthResult<'signed_in', {
|
|
202
|
+
session: PublicSession;
|
|
203
|
+
}>>;
|
|
204
|
+
/** Signs in with the code that came in the same mail as the link, for somebody reading it on another device. */
|
|
205
|
+
emailCode(form: {
|
|
206
|
+
code: string;
|
|
207
|
+
}): Promise<AuthResult<'signed_in', {
|
|
208
|
+
session: PublicSession;
|
|
209
|
+
}>>;
|
|
210
|
+
/** Sends the browser to Cauthy's page to use a passkey; it comes back signed in, at `returnTo`. */
|
|
211
|
+
passkey(options?: {
|
|
212
|
+
returnTo?: string;
|
|
213
|
+
locale?: string;
|
|
214
|
+
}): void;
|
|
215
|
+
/** Where `passkey` sends the browser, for a plain link. */
|
|
216
|
+
passkeyUrl(options?: {
|
|
217
|
+
returnTo?: string;
|
|
218
|
+
locale?: string;
|
|
219
|
+
}): string;
|
|
220
|
+
/** Sends the browser to the provider; it comes back signed in, at `returnTo`. */
|
|
221
|
+
social(provider: string, options?: {
|
|
222
|
+
returnTo?: string;
|
|
223
|
+
}): void;
|
|
224
|
+
/** Where `social` sends the browser, for a plain link. */
|
|
225
|
+
socialUrl(provider: string, options?: {
|
|
226
|
+
returnTo?: string;
|
|
227
|
+
}): string;
|
|
228
|
+
};
|
|
229
|
+
signUp: {
|
|
230
|
+
/** `verification_required`: the account exists and must open the link Cauthy mailed before it can sign in. */
|
|
231
|
+
email(form: {
|
|
232
|
+
email: string;
|
|
233
|
+
password: string;
|
|
234
|
+
name?: string;
|
|
235
|
+
}): Promise<AuthResult<'signed_in', {
|
|
236
|
+
session: PublicSession;
|
|
237
|
+
}> | AuthResult<'verification_required', {
|
|
238
|
+
email: string;
|
|
239
|
+
}>>;
|
|
240
|
+
};
|
|
241
|
+
/** Mails a link to choose a new password. The answer is the same whether or not the address has an account. */
|
|
242
|
+
forgotPassword(form: {
|
|
243
|
+
email: string;
|
|
244
|
+
}): Promise<AuthResult<'sent'>>;
|
|
245
|
+
/** Sets the new password, with the token the mailed link opened the page with (`token`). */
|
|
246
|
+
resetPassword(form: {
|
|
247
|
+
token: string;
|
|
248
|
+
password: string;
|
|
249
|
+
}): Promise<AuthResult<'changed'>>;
|
|
250
|
+
/** Confirms the address, with the token the mailed link opened the page with (`token`). */
|
|
251
|
+
verifyEmail(form: {
|
|
252
|
+
token: string;
|
|
253
|
+
}): Promise<AuthResult<'verified'>>;
|
|
254
|
+
signOut(): Promise<AuthResult<'signed_out'>>;
|
|
255
|
+
/** The signed-in person's own account. */
|
|
256
|
+
account: AccountClient;
|
|
257
|
+
/** Who is signed in, or null. */
|
|
258
|
+
getSession(): Promise<PublicSession | null>;
|
|
259
|
+
methods(): Promise<AuthMethods>;
|
|
260
|
+
/**
|
|
261
|
+
* How the workspace's forms look — colours, corners, typeface — as a person
|
|
262
|
+
* set it in Cauthy's dashboard. Read once per page; null when Cauthy cannot say.
|
|
263
|
+
*/
|
|
264
|
+
look(): Promise<CauthyTheme | null>;
|
|
265
|
+
}
|
|
266
|
+
interface AuthClientOptions {
|
|
267
|
+
/** Where the server mounted the routes. Default: `/api/auth`. */
|
|
268
|
+
basePath?: string;
|
|
269
|
+
fetch?: typeof fetch;
|
|
270
|
+
}
|
|
271
|
+
declare function createAuthClient(options?: AuthClientOptions): AuthClient;
|
|
272
|
+
|
|
273
|
+
export { type Account, type AccountClient, type AccountSession, type AuthClient, type AuthClientOptions, type AuthError, AuthField, type AuthMethods, type AuthResult, type LinkedIdentity, type SessionState, type SessionStore, type SessionStoreOptions, createAuthClient, createSessionStore };
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import { CauthyTheme } from './theme.js';
|
|
2
|
+
import { i as PublicSession } from './system-DhRr_WxR.js';
|
|
3
|
+
import { A as AuthField } from './validate-B_iC-4y8.js';
|
|
4
|
+
export { F as FieldProblem, M as MIN_PASSWORD, c as checkCode, a as checkEmail, b as checkName, d as checkNewPassword, e as checkPassword } from './validate-B_iC-4y8.js';
|
|
5
|
+
import 'jose';
|
|
6
|
+
|
|
7
|
+
interface SessionState {
|
|
8
|
+
/** The signed-in person and their organizations, or null. */
|
|
9
|
+
session: PublicSession | null;
|
|
10
|
+
status: 'loading' | 'authenticated' | 'unauthenticated';
|
|
11
|
+
}
|
|
12
|
+
interface SessionStoreOptions extends AuthClientOptions {
|
|
13
|
+
/**
|
|
14
|
+
* The session the server already read while rendering (SSR): the first
|
|
15
|
+
* paint is then right, with no "loading". `null` means "nobody"; leave it
|
|
16
|
+
* out when the server did not look.
|
|
17
|
+
*/
|
|
18
|
+
initialSession?: PublicSession | null;
|
|
19
|
+
}
|
|
20
|
+
interface SessionStore {
|
|
21
|
+
/** What is known now. */
|
|
22
|
+
get(): SessionState;
|
|
23
|
+
/** Calls `listener` now and on every change. Answers how to stop. */
|
|
24
|
+
subscribe(listener: (state: SessionState) => void): () => void;
|
|
25
|
+
/** Asks the server again who is signed in. */
|
|
26
|
+
refresh(): Promise<PublicSession | null>;
|
|
27
|
+
/** Sends the browser to Cauthy's page to sign in, and back to `returnTo` (default: where it is now). */
|
|
28
|
+
signIn(options?: {
|
|
29
|
+
returnTo?: string;
|
|
30
|
+
locale?: string;
|
|
31
|
+
prompt?: 'login';
|
|
32
|
+
}): void;
|
|
33
|
+
/** Signs out of this application and of Cauthy in this browser. */
|
|
34
|
+
signOut(): void;
|
|
35
|
+
/** Where the person looks after their account on Cauthy's page. */
|
|
36
|
+
accountUrl(returnTo?: string): string;
|
|
37
|
+
/**
|
|
38
|
+
* The functions of an application's own screens. They are
|
|
39
|
+
* `createAuthClient()`'s, and what changes who is signed in is heard by the
|
|
40
|
+
* subscribers with no reload.
|
|
41
|
+
*/
|
|
42
|
+
auth: AuthClient;
|
|
43
|
+
/** Where the server mounted the routes. */
|
|
44
|
+
basePath: string;
|
|
45
|
+
}
|
|
46
|
+
declare function createSessionStore(options?: SessionStoreOptions): SessionStore;
|
|
47
|
+
|
|
48
|
+
/** What went wrong, in a form the screen can show. */
|
|
49
|
+
interface AuthError {
|
|
50
|
+
/** Stable, for translating: `invalid_credentials`, `invalid_email`, `too_short`, `email_taken`, `unavailable`… */
|
|
51
|
+
code: string;
|
|
52
|
+
message: string;
|
|
53
|
+
/** The input it is about, when it is about one. */
|
|
54
|
+
field?: AuthField;
|
|
55
|
+
}
|
|
56
|
+
type AuthResult<S extends string, More = unknown> = ({
|
|
57
|
+
ok: true;
|
|
58
|
+
status: S;
|
|
59
|
+
} & More) | {
|
|
60
|
+
ok: false;
|
|
61
|
+
error: AuthError;
|
|
62
|
+
};
|
|
63
|
+
/** What the screen may offer. */
|
|
64
|
+
interface AuthMethods {
|
|
65
|
+
/** The providers the workspace signs people in with: `{ id: 'google', name: 'Google' }`. */
|
|
66
|
+
providers: {
|
|
67
|
+
id: string;
|
|
68
|
+
name: string;
|
|
69
|
+
}[];
|
|
70
|
+
/** Whether people may create an account themselves. */
|
|
71
|
+
signUp: boolean;
|
|
72
|
+
magicLink: boolean;
|
|
73
|
+
/** Whether to offer a passkey. It is asked for on Cauthy's page: the person goes there for that step and comes back signed in. */
|
|
74
|
+
passkey: boolean;
|
|
75
|
+
}
|
|
76
|
+
/** A person's own account, as their account screen shows it. */
|
|
77
|
+
interface Account {
|
|
78
|
+
id: string;
|
|
79
|
+
email: string;
|
|
80
|
+
name: string;
|
|
81
|
+
emailVerified: boolean;
|
|
82
|
+
/** False for an account that only signs in through a provider: it has no current password to ask for. */
|
|
83
|
+
hasPassword: boolean;
|
|
84
|
+
mfaEnabled: boolean;
|
|
85
|
+
}
|
|
86
|
+
/** Somewhere the person is signed in. Moments are UTC. */
|
|
87
|
+
interface AccountSession {
|
|
88
|
+
/** "Mac · Chrome", or "" when the browser did not say. */
|
|
89
|
+
device: string;
|
|
90
|
+
ip: string;
|
|
91
|
+
createdAt: string;
|
|
92
|
+
expiresAt: string;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* The signed-in person's own account. What weakens it — the password, the
|
|
96
|
+
* second step, its recovery codes — asks for the current password again.
|
|
97
|
+
*/
|
|
98
|
+
/** A provider the account can also sign in with. */
|
|
99
|
+
interface LinkedIdentity {
|
|
100
|
+
provider: string;
|
|
101
|
+
/** The address the provider has for the person, when it said. */
|
|
102
|
+
email: string;
|
|
103
|
+
name: string;
|
|
104
|
+
/** When it was linked, in UTC (ISO 8601). */
|
|
105
|
+
linkedAt: string;
|
|
106
|
+
}
|
|
107
|
+
interface AccountClient {
|
|
108
|
+
/** The account, or null when nobody is signed in. */
|
|
109
|
+
get(): Promise<Account | null>;
|
|
110
|
+
update(form: {
|
|
111
|
+
name: string;
|
|
112
|
+
}): Promise<AuthResult<'saved', {
|
|
113
|
+
account: Account;
|
|
114
|
+
}>>;
|
|
115
|
+
/** Ends every other session of the account; this one stays signed in. */
|
|
116
|
+
changePassword(form: {
|
|
117
|
+
password: string;
|
|
118
|
+
newPassword: string;
|
|
119
|
+
}): Promise<AuthResult<'changed', {
|
|
120
|
+
signedIn: boolean;
|
|
121
|
+
}>>;
|
|
122
|
+
mfa: {
|
|
123
|
+
/** Starts turning the second step on: show `secret` (or `otpauthUri` as a QR code) to add to an authenticator app, then call `verify`. */
|
|
124
|
+
setup(form: {
|
|
125
|
+
password: string;
|
|
126
|
+
}): Promise<AuthResult<'started', {
|
|
127
|
+
secret: string;
|
|
128
|
+
otpauthUri: string;
|
|
129
|
+
}>>;
|
|
130
|
+
/** Turns it on with a code from the app. `recoveryCodes` are shown this once. */
|
|
131
|
+
verify(form: {
|
|
132
|
+
code: string;
|
|
133
|
+
}): Promise<AuthResult<'enabled', {
|
|
134
|
+
recoveryCodes: string[];
|
|
135
|
+
}>>;
|
|
136
|
+
disable(form: {
|
|
137
|
+
password: string;
|
|
138
|
+
}): Promise<AuthResult<'disabled'>>;
|
|
139
|
+
/** New recovery codes; the earlier ones stop working. */
|
|
140
|
+
recoveryCodes(form: {
|
|
141
|
+
password: string;
|
|
142
|
+
}): Promise<AuthResult<'renewed', {
|
|
143
|
+
recoveryCodes: string[];
|
|
144
|
+
}>>;
|
|
145
|
+
};
|
|
146
|
+
/**
|
|
147
|
+
* Asks to sign in with another address. Nothing changes yet: the new address
|
|
148
|
+
* is mailed a link to confirm it, and once it is confirmed the old one is
|
|
149
|
+
* told, with a link that undoes it. Both open Cauthy's own page.
|
|
150
|
+
*/
|
|
151
|
+
changeEmail(form: {
|
|
152
|
+
email: string;
|
|
153
|
+
password: string;
|
|
154
|
+
}): Promise<AuthResult<'sent', {
|
|
155
|
+
email: string;
|
|
156
|
+
}>>;
|
|
157
|
+
/** The providers (Google…) the account can also sign in with. */
|
|
158
|
+
identities(): Promise<LinkedIdentity[]>;
|
|
159
|
+
/**
|
|
160
|
+
* Sends the browser to the provider, to link it to the account; it comes back
|
|
161
|
+
* at `returnTo` with `?linked=<provider>`, or `?auth_error=<code>`.
|
|
162
|
+
*/
|
|
163
|
+
link(provider: string, options?: {
|
|
164
|
+
returnTo?: string;
|
|
165
|
+
}): void;
|
|
166
|
+
/** Where `link` sends the browser, for a plain link. */
|
|
167
|
+
linkUrl(provider: string, options?: {
|
|
168
|
+
returnTo?: string;
|
|
169
|
+
}): string;
|
|
170
|
+
/** The account stops signing in with that provider. Refused when it would be left with no way to sign in. */
|
|
171
|
+
unlink(provider: string): Promise<AuthResult<'unlinked', {
|
|
172
|
+
provider: string;
|
|
173
|
+
}>>;
|
|
174
|
+
/** Where the account is signed in. */
|
|
175
|
+
sessions(): Promise<AccountSession[]>;
|
|
176
|
+
/** Signs the account out everywhere, here too. */
|
|
177
|
+
signOutEverywhere(): Promise<AuthResult<'signed_out'>>;
|
|
178
|
+
}
|
|
179
|
+
interface AuthClient {
|
|
180
|
+
signIn: {
|
|
181
|
+
/** With address and password. `mfa_required`: ask for the code and call `signIn.mfa`. */
|
|
182
|
+
email(form: {
|
|
183
|
+
email: string;
|
|
184
|
+
password: string;
|
|
185
|
+
}): Promise<AuthResult<'signed_in', {
|
|
186
|
+
session: PublicSession;
|
|
187
|
+
}> | AuthResult<'mfa_required'>>;
|
|
188
|
+
/** The second step: the code of the authenticator app, or a recovery code. */
|
|
189
|
+
mfa(form: {
|
|
190
|
+
code: string;
|
|
191
|
+
}): Promise<AuthResult<'signed_in', {
|
|
192
|
+
session: PublicSession;
|
|
193
|
+
}>>;
|
|
194
|
+
/** Mails a link that signs the person in. The answer is the same whether or not the address has an account. */
|
|
195
|
+
magicLink(form: {
|
|
196
|
+
email: string;
|
|
197
|
+
}): Promise<AuthResult<'sent'>>;
|
|
198
|
+
/** Signs in with the token the mailed link opened the page with (`ml_token`). */
|
|
199
|
+
magicLinkVerify(form: {
|
|
200
|
+
token: string;
|
|
201
|
+
}): Promise<AuthResult<'signed_in', {
|
|
202
|
+
session: PublicSession;
|
|
203
|
+
}>>;
|
|
204
|
+
/** Signs in with the code that came in the same mail as the link, for somebody reading it on another device. */
|
|
205
|
+
emailCode(form: {
|
|
206
|
+
code: string;
|
|
207
|
+
}): Promise<AuthResult<'signed_in', {
|
|
208
|
+
session: PublicSession;
|
|
209
|
+
}>>;
|
|
210
|
+
/** Sends the browser to Cauthy's page to use a passkey; it comes back signed in, at `returnTo`. */
|
|
211
|
+
passkey(options?: {
|
|
212
|
+
returnTo?: string;
|
|
213
|
+
locale?: string;
|
|
214
|
+
}): void;
|
|
215
|
+
/** Where `passkey` sends the browser, for a plain link. */
|
|
216
|
+
passkeyUrl(options?: {
|
|
217
|
+
returnTo?: string;
|
|
218
|
+
locale?: string;
|
|
219
|
+
}): string;
|
|
220
|
+
/** Sends the browser to the provider; it comes back signed in, at `returnTo`. */
|
|
221
|
+
social(provider: string, options?: {
|
|
222
|
+
returnTo?: string;
|
|
223
|
+
}): void;
|
|
224
|
+
/** Where `social` sends the browser, for a plain link. */
|
|
225
|
+
socialUrl(provider: string, options?: {
|
|
226
|
+
returnTo?: string;
|
|
227
|
+
}): string;
|
|
228
|
+
};
|
|
229
|
+
signUp: {
|
|
230
|
+
/** `verification_required`: the account exists and must open the link Cauthy mailed before it can sign in. */
|
|
231
|
+
email(form: {
|
|
232
|
+
email: string;
|
|
233
|
+
password: string;
|
|
234
|
+
name?: string;
|
|
235
|
+
}): Promise<AuthResult<'signed_in', {
|
|
236
|
+
session: PublicSession;
|
|
237
|
+
}> | AuthResult<'verification_required', {
|
|
238
|
+
email: string;
|
|
239
|
+
}>>;
|
|
240
|
+
};
|
|
241
|
+
/** Mails a link to choose a new password. The answer is the same whether or not the address has an account. */
|
|
242
|
+
forgotPassword(form: {
|
|
243
|
+
email: string;
|
|
244
|
+
}): Promise<AuthResult<'sent'>>;
|
|
245
|
+
/** Sets the new password, with the token the mailed link opened the page with (`token`). */
|
|
246
|
+
resetPassword(form: {
|
|
247
|
+
token: string;
|
|
248
|
+
password: string;
|
|
249
|
+
}): Promise<AuthResult<'changed'>>;
|
|
250
|
+
/** Confirms the address, with the token the mailed link opened the page with (`token`). */
|
|
251
|
+
verifyEmail(form: {
|
|
252
|
+
token: string;
|
|
253
|
+
}): Promise<AuthResult<'verified'>>;
|
|
254
|
+
signOut(): Promise<AuthResult<'signed_out'>>;
|
|
255
|
+
/** The signed-in person's own account. */
|
|
256
|
+
account: AccountClient;
|
|
257
|
+
/** Who is signed in, or null. */
|
|
258
|
+
getSession(): Promise<PublicSession | null>;
|
|
259
|
+
methods(): Promise<AuthMethods>;
|
|
260
|
+
/**
|
|
261
|
+
* How the workspace's forms look — colours, corners, typeface — as a person
|
|
262
|
+
* set it in Cauthy's dashboard. Read once per page; null when Cauthy cannot say.
|
|
263
|
+
*/
|
|
264
|
+
look(): Promise<CauthyTheme | null>;
|
|
265
|
+
}
|
|
266
|
+
interface AuthClientOptions {
|
|
267
|
+
/** Where the server mounted the routes. Default: `/api/auth`. */
|
|
268
|
+
basePath?: string;
|
|
269
|
+
fetch?: typeof fetch;
|
|
270
|
+
}
|
|
271
|
+
declare function createAuthClient(options?: AuthClientOptions): AuthClient;
|
|
272
|
+
|
|
273
|
+
export { type Account, type AccountClient, type AccountSession, type AuthClient, type AuthClientOptions, type AuthError, AuthField, type AuthMethods, type AuthResult, type LinkedIdentity, type SessionState, type SessionStore, type SessionStoreOptions, createAuthClient, createSessionStore };
|