@wtfalch/auth 0.14.0 → 0.15.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/dist/auth.d.ts +24 -3
- package/dist/auth.js +20 -0
- package/package.json +1 -1
package/dist/auth.d.ts
CHANGED
|
@@ -131,15 +131,21 @@ export interface Completed {
|
|
|
131
131
|
location: string;
|
|
132
132
|
cookies: SetCookie[];
|
|
133
133
|
}
|
|
134
|
-
/**
|
|
135
|
-
|
|
134
|
+
/**
|
|
135
|
+
* A person signed in without the browser driving the flow -- from a link, a
|
|
136
|
+
* password reset, or headless credentials. `E` is whichever entry point's
|
|
137
|
+
* own error vocabulary applies: `ResetError` for a link or reset code (the
|
|
138
|
+
* default, so `followLink` and `resetPassword` are unchanged), `SignInError`
|
|
139
|
+
* for a password.
|
|
140
|
+
*/
|
|
141
|
+
export type SignedIn<E = ResetError> = {
|
|
136
142
|
ok: true;
|
|
137
143
|
location: string;
|
|
138
144
|
cookies: SetCookie[];
|
|
139
145
|
hosted?: true;
|
|
140
146
|
} | {
|
|
141
147
|
ok: false;
|
|
142
|
-
error:
|
|
148
|
+
error: E;
|
|
143
149
|
message: string;
|
|
144
150
|
};
|
|
145
151
|
export interface QrSignInStart {
|
|
@@ -202,6 +208,21 @@ export interface Auth {
|
|
|
202
208
|
code: string;
|
|
203
209
|
next?: string;
|
|
204
210
|
}, requestHeaders?: Headers): Promise<SignedIn>;
|
|
211
|
+
/**
|
|
212
|
+
* `signIn` as data, for a caller with no browser to carry through the OIDC
|
|
213
|
+
* redirect -- a CLI, a desktop app, or a server signing in on a person's
|
|
214
|
+
* behalf. There is no `authRequestId` to receive, because this runs its
|
|
215
|
+
* own transaction and finishes it itself: `ok: true` already carries the
|
|
216
|
+
* session, with no `complete()` call left to make. The same two checks as
|
|
217
|
+
* `followLink` apply -- an `ok: true` with an empty `cookies` means the
|
|
218
|
+
* issuer handed off to hosted login, and the cookie name is fixed, so the
|
|
219
|
+
* caller decides where the session goes.
|
|
220
|
+
*/
|
|
221
|
+
signInWithPassword(input: {
|
|
222
|
+
email: string;
|
|
223
|
+
password: string;
|
|
224
|
+
next?: string;
|
|
225
|
+
}, requestHeaders?: Headers): Promise<SignedIn<SignInError>>;
|
|
205
226
|
/** Emails a fresh verification link. Says nothing about whether the address exists. */
|
|
206
227
|
resendVerification(email: string, next?: string): Promise<void>;
|
|
207
228
|
/** Emails a password-reset link to {basePath}/reset?userId=&code=. Says nothing about whether the address exists. */
|
package/dist/auth.js
CHANGED
|
@@ -541,6 +541,25 @@ export function createAuth(input) {
|
|
|
541
541
|
return { ok: false, error: signInError(error) };
|
|
542
542
|
}
|
|
543
543
|
};
|
|
544
|
+
const signInWithPassword = async ({ email, password, next }, requestHeaders) => {
|
|
545
|
+
try {
|
|
546
|
+
const flow = await serverFlow();
|
|
547
|
+
const completed = await finishOrHandoff(() => broker().signIn({ authRequestId: flow.id, email, password }), flow, safeNextPath(next, options().afterLogin), requestHeaders);
|
|
548
|
+
emit({ type: 'signIn', email });
|
|
549
|
+
return { ok: true, ...completed };
|
|
550
|
+
}
|
|
551
|
+
catch (error) {
|
|
552
|
+
const code = signInError(error);
|
|
553
|
+
// `signInError` collapses everything the broker can say into one of
|
|
554
|
+
// four codes; only a real `BrokerError` carries a sentence worth
|
|
555
|
+
// showing; a transient failure gets the same generic message every
|
|
556
|
+
// other headless entry point uses for `unavailable`.
|
|
557
|
+
const message = code !== 'unavailable' && error instanceof BrokerError
|
|
558
|
+
? (error.detail ?? error.error)
|
|
559
|
+
: 'the sign-in service did not answer';
|
|
560
|
+
return { ok: false, error: code, message };
|
|
561
|
+
}
|
|
562
|
+
};
|
|
544
563
|
const signUp = async ({ authRequestId, ...user }) => {
|
|
545
564
|
try {
|
|
546
565
|
const redirectTo = await broker().signUp({ authRequestId, ...user });
|
|
@@ -814,6 +833,7 @@ export function createAuth(input) {
|
|
|
814
833
|
endSession,
|
|
815
834
|
authRequest,
|
|
816
835
|
signIn,
|
|
836
|
+
signInWithPassword,
|
|
817
837
|
signUp,
|
|
818
838
|
startPasskeyRegistration,
|
|
819
839
|
finishPasskeyRegistration,
|
package/package.json
CHANGED