better-auth-cognito-native 0.1.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/client.d.mts +148 -0
- package/dist/client.mjs +179 -0
- package/dist/config-C3_h3skc.d.mts +35 -0
- package/dist/config.d.mts +2 -0
- package/dist/config.mjs +39 -0
- package/dist/error-codes-O-Ljx2JX.mjs +30 -0
- package/dist/index-D4C-gqBy.d.mts +213 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.mjs +679 -0
- package/package.json +59 -0
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { n as cognitoPlugin } from "./index-D4C-gqBy.mjs";
|
|
2
|
+
import { CognitoIdentityProviderClient } from "@aws-sdk/client-cognito-identity-provider";
|
|
3
|
+
import * as z from "zod";
|
|
4
|
+
import * as _$better_auth_client0 from "better-auth/client";
|
|
5
|
+
//#region src/routes.d.ts
|
|
6
|
+
declare const cognitoStartPasskeySignInBodySchema: z.ZodObject<{
|
|
7
|
+
email: z.ZodEmail;
|
|
8
|
+
}, z.core.$strip>;
|
|
9
|
+
declare const cognitoCompletePasskeySignInBodySchema: z.ZodObject<{
|
|
10
|
+
email: z.ZodEmail;
|
|
11
|
+
credential: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
12
|
+
session: z.ZodString;
|
|
13
|
+
rememberMe: z.ZodOptional<z.ZodBoolean>;
|
|
14
|
+
}, z.core.$strip>;
|
|
15
|
+
declare const cognitoCompletePasskeyRegistrationBodySchema: z.ZodObject<{
|
|
16
|
+
credential: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
17
|
+
}, z.core.$strip>;
|
|
18
|
+
declare const cognitoUpdateUserAttributesBodySchema: z.ZodObject<{
|
|
19
|
+
attributes: z.ZodArray<z.ZodObject<{
|
|
20
|
+
Name: z.ZodString;
|
|
21
|
+
Value: z.ZodString;
|
|
22
|
+
}, z.core.$strip>>;
|
|
23
|
+
}, z.core.$strip>;
|
|
24
|
+
type CognitoStartPasskeySignInInput = z.infer<typeof cognitoStartPasskeySignInBodySchema>;
|
|
25
|
+
type CognitoCompletePasskeySignInInput = z.infer<typeof cognitoCompletePasskeySignInBodySchema>;
|
|
26
|
+
type CognitoCompletePasskeyRegistrationInput = z.infer<typeof cognitoCompletePasskeyRegistrationBodySchema>;
|
|
27
|
+
type CognitoUpdateUserAttributesInput = z.infer<typeof cognitoUpdateUserAttributesBodySchema>;
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region src/client.d.ts
|
|
30
|
+
/** Minimal interface required by the standalone browser helpers. */
|
|
31
|
+
interface CognitoPasskeyActions {
|
|
32
|
+
startPasskeySignIn(data: CognitoStartPasskeySignInInput): Promise<{
|
|
33
|
+
data: {
|
|
34
|
+
session: string;
|
|
35
|
+
requestOptions: Record<string, unknown>;
|
|
36
|
+
} | null;
|
|
37
|
+
error: {
|
|
38
|
+
message?: string;
|
|
39
|
+
} | null;
|
|
40
|
+
}>;
|
|
41
|
+
completePasskeySignIn(data: CognitoCompletePasskeySignInInput): Promise<{
|
|
42
|
+
data: unknown;
|
|
43
|
+
error: {
|
|
44
|
+
message?: string;
|
|
45
|
+
} | null;
|
|
46
|
+
}>;
|
|
47
|
+
startPasskeyRegistration(): Promise<{
|
|
48
|
+
data: {
|
|
49
|
+
credentialCreationOptions: Record<string, unknown>;
|
|
50
|
+
} | null;
|
|
51
|
+
error: {
|
|
52
|
+
message?: string;
|
|
53
|
+
} | null;
|
|
54
|
+
}>;
|
|
55
|
+
completePasskeyRegistration(data: CognitoCompletePasskeyRegistrationInput): Promise<{
|
|
56
|
+
data: unknown;
|
|
57
|
+
error: {
|
|
58
|
+
message?: string;
|
|
59
|
+
} | null;
|
|
60
|
+
}>;
|
|
61
|
+
}
|
|
62
|
+
interface CognitoCodeDeliveryDetails {
|
|
63
|
+
Destination?: string;
|
|
64
|
+
DeliveryMedium?: string;
|
|
65
|
+
AttributeName?: string;
|
|
66
|
+
}
|
|
67
|
+
type PasskeySignInResult = {
|
|
68
|
+
success: true;
|
|
69
|
+
} | {
|
|
70
|
+
success: false;
|
|
71
|
+
cancelled: boolean;
|
|
72
|
+
noPasskey: boolean;
|
|
73
|
+
error: string;
|
|
74
|
+
};
|
|
75
|
+
type PasskeyRegistrationResult = {
|
|
76
|
+
success: true;
|
|
77
|
+
} | {
|
|
78
|
+
success: false;
|
|
79
|
+
cancelled: boolean;
|
|
80
|
+
error: string;
|
|
81
|
+
};
|
|
82
|
+
declare function signInWithPasskey(actions: CognitoPasskeyActions, email: string, opts?: {
|
|
83
|
+
rememberMe?: boolean;
|
|
84
|
+
}): Promise<PasskeySignInResult>;
|
|
85
|
+
declare function registerPasskey(actions: CognitoPasskeyActions): Promise<PasskeyRegistrationResult>;
|
|
86
|
+
declare function cognitoClientPlugin(): {
|
|
87
|
+
id: "cognito";
|
|
88
|
+
$InferServerPlugin: ReturnType<typeof cognitoPlugin>;
|
|
89
|
+
pathMethods: {
|
|
90
|
+
"/cognito/sign-up": "POST";
|
|
91
|
+
"/cognito/confirm-sign-up": "POST";
|
|
92
|
+
"/cognito/resend-confirmation": "POST";
|
|
93
|
+
"/cognito/forgot-password": "POST";
|
|
94
|
+
"/cognito/confirm-forgot-password": "POST";
|
|
95
|
+
"/cognito/sign-in": "POST";
|
|
96
|
+
"/cognito/new-password": "POST";
|
|
97
|
+
"/cognito/sign-out": "POST";
|
|
98
|
+
"/cognito/passkey/sign-in/start": "POST";
|
|
99
|
+
"/cognito/passkey/sign-in/complete": "POST";
|
|
100
|
+
"/cognito/passkey/register/start": "POST";
|
|
101
|
+
"/cognito/passkey/register/complete": "POST";
|
|
102
|
+
};
|
|
103
|
+
$ERROR_CODES: Record<string, {
|
|
104
|
+
code: string;
|
|
105
|
+
message: string;
|
|
106
|
+
}>;
|
|
107
|
+
getActions: ($fetch: _$better_auth_client0.BetterFetch) => {
|
|
108
|
+
cognito: {
|
|
109
|
+
userAttributes: {
|
|
110
|
+
get: () => Promise<{
|
|
111
|
+
data: {
|
|
112
|
+
attributes: {
|
|
113
|
+
Name?: string;
|
|
114
|
+
Value?: string;
|
|
115
|
+
}[];
|
|
116
|
+
};
|
|
117
|
+
error: null;
|
|
118
|
+
} | {
|
|
119
|
+
data: null;
|
|
120
|
+
error: {
|
|
121
|
+
message?: string | undefined;
|
|
122
|
+
status: number;
|
|
123
|
+
statusText: string;
|
|
124
|
+
};
|
|
125
|
+
}>;
|
|
126
|
+
update: (data: CognitoUpdateUserAttributesInput) => Promise<{
|
|
127
|
+
data: null;
|
|
128
|
+
error: {
|
|
129
|
+
message?: string | undefined;
|
|
130
|
+
status: number;
|
|
131
|
+
statusText: string;
|
|
132
|
+
};
|
|
133
|
+
} | {
|
|
134
|
+
data: {
|
|
135
|
+
updated: boolean;
|
|
136
|
+
};
|
|
137
|
+
error: null;
|
|
138
|
+
}>;
|
|
139
|
+
};
|
|
140
|
+
signInWithPasskey: (email: string, opts?: {
|
|
141
|
+
rememberMe?: boolean;
|
|
142
|
+
}) => Promise<PasskeySignInResult>;
|
|
143
|
+
registerPasskey: () => Promise<PasskeyRegistrationResult>;
|
|
144
|
+
};
|
|
145
|
+
};
|
|
146
|
+
};
|
|
147
|
+
//#endregion
|
|
148
|
+
export { CognitoCodeDeliveryDetails, CognitoPasskeyActions, PasskeyRegistrationResult, PasskeySignInResult, cognitoClientPlugin, registerPasskey, signInWithPasskey };
|
package/dist/client.mjs
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { t as COGNITO_ERROR_CODES } from "./error-codes-O-Ljx2JX.mjs";
|
|
2
|
+
import { startAuthentication, startRegistration } from "@simplewebauthn/browser";
|
|
3
|
+
//#region src/client.ts
|
|
4
|
+
function isBrowserCancelError(err) {
|
|
5
|
+
const msg = err instanceof Error ? err.message : "";
|
|
6
|
+
return msg.includes("cancelled") || msg.includes("NotAllowedError");
|
|
7
|
+
}
|
|
8
|
+
function isNoPasskeyError(message) {
|
|
9
|
+
const m = message.toLowerCase();
|
|
10
|
+
return m.includes("no passkeys registered") || m.includes("no passkey options returned") || m.includes("passkey sign-in is not available");
|
|
11
|
+
}
|
|
12
|
+
async function signInWithPasskey(actions, email, opts) {
|
|
13
|
+
const { data: startData, error: startError } = await actions.startPasskeySignIn({ email });
|
|
14
|
+
if (startError) {
|
|
15
|
+
const message = startError.message ?? "Failed to start passkey sign-in";
|
|
16
|
+
return {
|
|
17
|
+
success: false,
|
|
18
|
+
cancelled: false,
|
|
19
|
+
noPasskey: isNoPasskeyError(message),
|
|
20
|
+
error: message
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
const { session, requestOptions } = startData;
|
|
24
|
+
let credential;
|
|
25
|
+
try {
|
|
26
|
+
credential = await startAuthentication({ optionsJSON: requestOptions });
|
|
27
|
+
} catch (err) {
|
|
28
|
+
return {
|
|
29
|
+
success: false,
|
|
30
|
+
cancelled: isBrowserCancelError(err),
|
|
31
|
+
noPasskey: false,
|
|
32
|
+
error: err instanceof Error ? err.message : "Passkey authentication failed"
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
const { error: completeError } = await actions.completePasskeySignIn({
|
|
36
|
+
email,
|
|
37
|
+
credential,
|
|
38
|
+
session,
|
|
39
|
+
rememberMe: opts?.rememberMe
|
|
40
|
+
});
|
|
41
|
+
if (completeError) return {
|
|
42
|
+
success: false,
|
|
43
|
+
cancelled: false,
|
|
44
|
+
noPasskey: false,
|
|
45
|
+
error: completeError.message ?? "Passkey verification failed"
|
|
46
|
+
};
|
|
47
|
+
return { success: true };
|
|
48
|
+
}
|
|
49
|
+
async function registerPasskey(actions) {
|
|
50
|
+
const { data: startData, error: startError } = await actions.startPasskeyRegistration();
|
|
51
|
+
if (startError || !startData) return {
|
|
52
|
+
success: false,
|
|
53
|
+
cancelled: false,
|
|
54
|
+
error: startError?.message ?? "Failed to start passkey registration"
|
|
55
|
+
};
|
|
56
|
+
let credential;
|
|
57
|
+
try {
|
|
58
|
+
credential = await startRegistration({ optionsJSON: startData.credentialCreationOptions });
|
|
59
|
+
} catch (err) {
|
|
60
|
+
return {
|
|
61
|
+
success: false,
|
|
62
|
+
cancelled: isBrowserCancelError(err),
|
|
63
|
+
error: err instanceof Error ? err.message : "Passkey registration failed"
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
const { error: completeError } = await actions.completePasskeyRegistration({ credential });
|
|
67
|
+
if (completeError) return {
|
|
68
|
+
success: false,
|
|
69
|
+
cancelled: false,
|
|
70
|
+
error: completeError.message ?? "Passkey registration failed"
|
|
71
|
+
};
|
|
72
|
+
return { success: true };
|
|
73
|
+
}
|
|
74
|
+
function cognitoClientPlugin() {
|
|
75
|
+
return {
|
|
76
|
+
id: "cognito",
|
|
77
|
+
$InferServerPlugin: {},
|
|
78
|
+
pathMethods: {
|
|
79
|
+
"/cognito/sign-up": "POST",
|
|
80
|
+
"/cognito/confirm-sign-up": "POST",
|
|
81
|
+
"/cognito/resend-confirmation": "POST",
|
|
82
|
+
"/cognito/forgot-password": "POST",
|
|
83
|
+
"/cognito/confirm-forgot-password": "POST",
|
|
84
|
+
"/cognito/sign-in": "POST",
|
|
85
|
+
"/cognito/new-password": "POST",
|
|
86
|
+
"/cognito/sign-out": "POST",
|
|
87
|
+
"/cognito/passkey/sign-in/start": "POST",
|
|
88
|
+
"/cognito/passkey/sign-in/complete": "POST",
|
|
89
|
+
"/cognito/passkey/register/start": "POST",
|
|
90
|
+
"/cognito/passkey/register/complete": "POST"
|
|
91
|
+
},
|
|
92
|
+
$ERROR_CODES: COGNITO_ERROR_CODES,
|
|
93
|
+
getActions: ($fetch) => ({ cognito: {
|
|
94
|
+
userAttributes: {
|
|
95
|
+
get: () => $fetch("/cognito/user-attributes", { method: "GET" }),
|
|
96
|
+
update: (data) => $fetch("/cognito/user-attributes", {
|
|
97
|
+
method: "POST",
|
|
98
|
+
body: data
|
|
99
|
+
})
|
|
100
|
+
},
|
|
101
|
+
signInWithPasskey: async (email, opts) => {
|
|
102
|
+
const { data: startData, error: startError } = await $fetch("/cognito/passkey/sign-in/start", {
|
|
103
|
+
method: "POST",
|
|
104
|
+
body: { email }
|
|
105
|
+
});
|
|
106
|
+
if (startError) {
|
|
107
|
+
const message = startError.message ?? "Failed to start passkey sign-in";
|
|
108
|
+
return {
|
|
109
|
+
success: false,
|
|
110
|
+
cancelled: false,
|
|
111
|
+
noPasskey: isNoPasskeyError(message),
|
|
112
|
+
error: message
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
const { session, requestOptions } = startData;
|
|
116
|
+
let credential;
|
|
117
|
+
try {
|
|
118
|
+
credential = await startAuthentication({ optionsJSON: requestOptions });
|
|
119
|
+
} catch (err) {
|
|
120
|
+
return {
|
|
121
|
+
success: false,
|
|
122
|
+
cancelled: isBrowserCancelError(err),
|
|
123
|
+
noPasskey: false,
|
|
124
|
+
error: err instanceof Error ? err.message : "Passkey authentication failed"
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
const { error: completeError } = await $fetch("/cognito/passkey/sign-in/complete", {
|
|
128
|
+
method: "POST",
|
|
129
|
+
body: {
|
|
130
|
+
email,
|
|
131
|
+
credential,
|
|
132
|
+
session,
|
|
133
|
+
rememberMe: opts?.rememberMe
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
if (completeError) return {
|
|
137
|
+
success: false,
|
|
138
|
+
cancelled: false,
|
|
139
|
+
noPasskey: false,
|
|
140
|
+
error: completeError.message ?? "Passkey verification failed"
|
|
141
|
+
};
|
|
142
|
+
return { success: true };
|
|
143
|
+
},
|
|
144
|
+
registerPasskey: async () => {
|
|
145
|
+
const { data: startData, error: startError } = await $fetch("/cognito/passkey/register/start", {
|
|
146
|
+
method: "POST",
|
|
147
|
+
body: {}
|
|
148
|
+
});
|
|
149
|
+
if (startError || !startData) return {
|
|
150
|
+
success: false,
|
|
151
|
+
cancelled: false,
|
|
152
|
+
error: startError?.message ?? "Failed to start passkey registration"
|
|
153
|
+
};
|
|
154
|
+
let credential;
|
|
155
|
+
try {
|
|
156
|
+
credential = await startRegistration({ optionsJSON: startData.credentialCreationOptions });
|
|
157
|
+
} catch (err) {
|
|
158
|
+
return {
|
|
159
|
+
success: false,
|
|
160
|
+
cancelled: isBrowserCancelError(err),
|
|
161
|
+
error: err instanceof Error ? err.message : "Passkey registration failed"
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
const { error: completeError } = await $fetch("/cognito/passkey/register/complete", {
|
|
165
|
+
method: "POST",
|
|
166
|
+
body: { credential }
|
|
167
|
+
});
|
|
168
|
+
if (completeError) return {
|
|
169
|
+
success: false,
|
|
170
|
+
cancelled: false,
|
|
171
|
+
error: completeError.message ?? "Passkey registration failed"
|
|
172
|
+
};
|
|
173
|
+
return { success: true };
|
|
174
|
+
}
|
|
175
|
+
} })
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
//#endregion
|
|
179
|
+
export { cognitoClientPlugin, registerPasskey, signInWithPasskey };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
2
|
+
interface CognitoPluginOptions {
|
|
3
|
+
/** AWS region, e.g. "ap-northeast-1" */
|
|
4
|
+
region: string;
|
|
5
|
+
/** Cognito User Pool ID */
|
|
6
|
+
userPoolId: string;
|
|
7
|
+
/** Cognito App Client ID */
|
|
8
|
+
clientId: string;
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/config.d.ts
|
|
12
|
+
type PasskeyMode = "disabled" | "optional";
|
|
13
|
+
interface CognitoPasskeyConfig {
|
|
14
|
+
mode: PasskeyMode;
|
|
15
|
+
userVerification?: "preferred" | "required";
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Returns the Cognito WebAuthn/passkey configuration for the user pool and app client.
|
|
19
|
+
*
|
|
20
|
+
* - "disabled" — WebAuthn not configured on the pool, or ALLOW_USER_AUTH not enabled on the client
|
|
21
|
+
* - "optional" — WebAuthn configured; passkey is offered but the user can fall back to password
|
|
22
|
+
*
|
|
23
|
+
* Note: WebAuthnConfiguration.UserVerification controls the passkey *ceremony* (whether the
|
|
24
|
+
* authenticator must perform a PIN/biometric check), not whether passkeys are enforced at the
|
|
25
|
+
* application level. Enforcing passkey-only sign-in is an app-level policy decision.
|
|
26
|
+
*
|
|
27
|
+
* Requires the IAM execution role to have:
|
|
28
|
+
* cognito-idp:GetUserPoolMfaConfig on the user pool
|
|
29
|
+
* cognito-idp:DescribeUserPoolClient on the user pool client
|
|
30
|
+
*
|
|
31
|
+
* Falls back to "optional" on any error (missing permissions, network, etc.).
|
|
32
|
+
*/
|
|
33
|
+
declare function getPasskeyConfig(opts: CognitoPluginOptions): Promise<CognitoPasskeyConfig>;
|
|
34
|
+
//#endregion
|
|
35
|
+
export { CognitoPluginOptions as i, PasskeyMode as n, getPasskeyConfig as r, CognitoPasskeyConfig as t };
|
package/dist/config.mjs
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { CognitoIdentityProviderClient, DescribeUserPoolClientCommand, GetUserPoolMfaConfigCommand } from "@aws-sdk/client-cognito-identity-provider";
|
|
2
|
+
//#region src/config.ts
|
|
3
|
+
/**
|
|
4
|
+
* Returns the Cognito WebAuthn/passkey configuration for the user pool and app client.
|
|
5
|
+
*
|
|
6
|
+
* - "disabled" — WebAuthn not configured on the pool, or ALLOW_USER_AUTH not enabled on the client
|
|
7
|
+
* - "optional" — WebAuthn configured; passkey is offered but the user can fall back to password
|
|
8
|
+
*
|
|
9
|
+
* Note: WebAuthnConfiguration.UserVerification controls the passkey *ceremony* (whether the
|
|
10
|
+
* authenticator must perform a PIN/biometric check), not whether passkeys are enforced at the
|
|
11
|
+
* application level. Enforcing passkey-only sign-in is an app-level policy decision.
|
|
12
|
+
*
|
|
13
|
+
* Requires the IAM execution role to have:
|
|
14
|
+
* cognito-idp:GetUserPoolMfaConfig on the user pool
|
|
15
|
+
* cognito-idp:DescribeUserPoolClient on the user pool client
|
|
16
|
+
*
|
|
17
|
+
* Falls back to "optional" on any error (missing permissions, network, etc.).
|
|
18
|
+
*/
|
|
19
|
+
async function getPasskeyConfig(opts) {
|
|
20
|
+
const client = new CognitoIdentityProviderClient({ region: opts.region });
|
|
21
|
+
try {
|
|
22
|
+
const [mfaResult, clientResult] = await Promise.all([client.send(new GetUserPoolMfaConfigCommand({ UserPoolId: opts.userPoolId })), client.send(new DescribeUserPoolClientCommand({
|
|
23
|
+
UserPoolId: opts.userPoolId,
|
|
24
|
+
ClientId: opts.clientId
|
|
25
|
+
}))]);
|
|
26
|
+
const webAuthnConfig = mfaResult.WebAuthnConfiguration;
|
|
27
|
+
const allowUserAuth = (clientResult.UserPoolClient?.ExplicitAuthFlows ?? []).includes("ALLOW_USER_AUTH");
|
|
28
|
+
if (!webAuthnConfig?.RelyingPartyId || !allowUserAuth) return { mode: "disabled" };
|
|
29
|
+
return {
|
|
30
|
+
mode: "optional",
|
|
31
|
+
userVerification: webAuthnConfig.UserVerification
|
|
32
|
+
};
|
|
33
|
+
} catch (error) {
|
|
34
|
+
console.error("Error fetching Cognito passkey configuration:", error);
|
|
35
|
+
return { mode: "optional" };
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
//#endregion
|
|
39
|
+
export { getPasskeyConfig };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//#region src/error-codes.ts
|
|
2
|
+
const COGNITO_ERROR_CODES = {
|
|
3
|
+
INVALID_CREDENTIALS: "Invalid email or password",
|
|
4
|
+
USER_NOT_FOUND: "User not found",
|
|
5
|
+
USER_NOT_CONFIRMED: "Account not confirmed. Please verify your email.",
|
|
6
|
+
ACCOUNT_ALREADY_EXISTS: "An account with this email already exists",
|
|
7
|
+
SIGN_UP_FAILED: "Failed to sign up",
|
|
8
|
+
FORGOT_PASSWORD_FAILED: "Failed to start password reset",
|
|
9
|
+
FORGOT_PASSWORD_CONFIRM_FAILED: "Failed to reset password",
|
|
10
|
+
CONFIRMATION_CODE_MISMATCH: "The confirmation code is invalid",
|
|
11
|
+
CONFIRMATION_CODE_EXPIRED: "The confirmation code has expired",
|
|
12
|
+
CONFIRMATION_FAILED: "Failed to confirm sign up",
|
|
13
|
+
RESEND_CONFIRMATION_FAILED: "Failed to resend confirmation code",
|
|
14
|
+
AUTH_SERVICE_ERROR: "Authentication service error",
|
|
15
|
+
NO_TOKEN_FROM_COGNITO: "No token returned from Cognito",
|
|
16
|
+
TOKEN_VERIFICATION_FAILED: "Token verification failed",
|
|
17
|
+
PASSKEYS_NOT_ENABLED: "Passkeys are not enabled for this user pool",
|
|
18
|
+
NO_PASSKEYS_REGISTERED: "This account has no passkeys registered",
|
|
19
|
+
PASSKEY_VERIFICATION_FAILED: "Passkey verification failed",
|
|
20
|
+
PASSKEY_NO_OPTIONS_RETURNED: "No passkey options returned",
|
|
21
|
+
NO_COGNITO_ACCESS_TOKEN: "No Cognito access token available",
|
|
22
|
+
PASSKEY_REGISTRATION_START_FAILED: "Failed to start passkey registration",
|
|
23
|
+
PASSKEY_REGISTRATION_FAILED: "Passkey registration failed",
|
|
24
|
+
PASSKEY_ORIGIN_NOT_ALLOWED: "Origin not allowed for passkey registration",
|
|
25
|
+
RELYING_PARTY_MISMATCH: "Relying party mismatch",
|
|
26
|
+
GET_USER_ATTRIBUTES_FAILED: "Failed to get user attributes",
|
|
27
|
+
UPDATE_USER_ATTRIBUTES_FAILED: "Failed to update user attributes"
|
|
28
|
+
};
|
|
29
|
+
//#endregion
|
|
30
|
+
export { COGNITO_ERROR_CODES as t };
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { i as CognitoPluginOptions } from "./config-C3_h3skc.mjs";
|
|
2
|
+
import * as _$_aws_sdk_client_cognito_identity_provider0 from "@aws-sdk/client-cognito-identity-provider";
|
|
3
|
+
import * as _$zod from "zod";
|
|
4
|
+
import * as _$better_auth0 from "better-auth";
|
|
5
|
+
import * as _$zod_v4_core0 from "zod/v4/core";
|
|
6
|
+
import * as _$_smithy_types0 from "@smithy/types";
|
|
7
|
+
|
|
8
|
+
//#region src/error-codes.d.ts
|
|
9
|
+
declare const COGNITO_ERROR_CODES: {
|
|
10
|
+
readonly INVALID_CREDENTIALS: "Invalid email or password";
|
|
11
|
+
readonly USER_NOT_FOUND: "User not found";
|
|
12
|
+
readonly USER_NOT_CONFIRMED: "Account not confirmed. Please verify your email.";
|
|
13
|
+
readonly ACCOUNT_ALREADY_EXISTS: "An account with this email already exists";
|
|
14
|
+
readonly SIGN_UP_FAILED: "Failed to sign up";
|
|
15
|
+
readonly FORGOT_PASSWORD_FAILED: "Failed to start password reset";
|
|
16
|
+
readonly FORGOT_PASSWORD_CONFIRM_FAILED: "Failed to reset password";
|
|
17
|
+
readonly CONFIRMATION_CODE_MISMATCH: "The confirmation code is invalid";
|
|
18
|
+
readonly CONFIRMATION_CODE_EXPIRED: "The confirmation code has expired";
|
|
19
|
+
readonly CONFIRMATION_FAILED: "Failed to confirm sign up";
|
|
20
|
+
readonly RESEND_CONFIRMATION_FAILED: "Failed to resend confirmation code";
|
|
21
|
+
readonly AUTH_SERVICE_ERROR: "Authentication service error";
|
|
22
|
+
readonly NO_TOKEN_FROM_COGNITO: "No token returned from Cognito";
|
|
23
|
+
readonly TOKEN_VERIFICATION_FAILED: "Token verification failed";
|
|
24
|
+
readonly PASSKEYS_NOT_ENABLED: "Passkeys are not enabled for this user pool";
|
|
25
|
+
readonly NO_PASSKEYS_REGISTERED: "This account has no passkeys registered";
|
|
26
|
+
readonly PASSKEY_VERIFICATION_FAILED: "Passkey verification failed";
|
|
27
|
+
readonly PASSKEY_NO_OPTIONS_RETURNED: "No passkey options returned";
|
|
28
|
+
readonly NO_COGNITO_ACCESS_TOKEN: "No Cognito access token available";
|
|
29
|
+
readonly PASSKEY_REGISTRATION_START_FAILED: "Failed to start passkey registration";
|
|
30
|
+
readonly PASSKEY_REGISTRATION_FAILED: "Passkey registration failed";
|
|
31
|
+
readonly PASSKEY_ORIGIN_NOT_ALLOWED: "Origin not allowed for passkey registration";
|
|
32
|
+
readonly RELYING_PARTY_MISMATCH: "Relying party mismatch";
|
|
33
|
+
readonly GET_USER_ATTRIBUTES_FAILED: "Failed to get user attributes";
|
|
34
|
+
readonly UPDATE_USER_ATTRIBUTES_FAILED: "Failed to update user attributes";
|
|
35
|
+
};
|
|
36
|
+
//#endregion
|
|
37
|
+
//#region src/index.d.ts
|
|
38
|
+
/**
|
|
39
|
+
* Better Auth server plugin for AWS Cognito.
|
|
40
|
+
*
|
|
41
|
+
* Registers endpoints:
|
|
42
|
+
* GET /cognito/tokens
|
|
43
|
+
* POST /cognito/sign-up
|
|
44
|
+
* POST /cognito/confirm-sign-up
|
|
45
|
+
* POST /cognito/resend-confirmation
|
|
46
|
+
* POST /cognito/forgot-password
|
|
47
|
+
* POST /cognito/confirm-forgot-password
|
|
48
|
+
* POST /cognito/sign-in
|
|
49
|
+
* POST /cognito/new-password
|
|
50
|
+
* POST /cognito/sign-out
|
|
51
|
+
* POST /cognito/passkey/sign-in/start
|
|
52
|
+
* POST /cognito/passkey/sign-in/complete
|
|
53
|
+
* POST /cognito/passkey/register/start
|
|
54
|
+
* POST /cognito/passkey/register/complete
|
|
55
|
+
*/
|
|
56
|
+
declare const cognitoPlugin: (opts: CognitoPluginOptions) => {
|
|
57
|
+
id: "cognito";
|
|
58
|
+
endpoints: {
|
|
59
|
+
cognitoGetTokens: _$better_auth0.StrictEndpoint<"/cognito/tokens", {
|
|
60
|
+
method: "GET";
|
|
61
|
+
}, {
|
|
62
|
+
accessToken: string | null;
|
|
63
|
+
idToken: string | null;
|
|
64
|
+
}>;
|
|
65
|
+
cognitoGetUserAttributes: _$better_auth0.StrictEndpoint<"/cognito/user-attributes", {
|
|
66
|
+
method: "GET";
|
|
67
|
+
}, {
|
|
68
|
+
attributes: _$_aws_sdk_client_cognito_identity_provider0.AttributeType[];
|
|
69
|
+
}>;
|
|
70
|
+
cognitoUpdateUserAttributes: _$better_auth0.StrictEndpoint<"/cognito/user-attributes", {
|
|
71
|
+
method: "POST";
|
|
72
|
+
body: _$zod.ZodObject<{
|
|
73
|
+
attributes: _$zod.ZodArray<_$zod.ZodObject<{
|
|
74
|
+
Name: _$zod.ZodString;
|
|
75
|
+
Value: _$zod.ZodString;
|
|
76
|
+
}, _$zod_v4_core0.$strip>>;
|
|
77
|
+
}, _$zod_v4_core0.$strip>;
|
|
78
|
+
}, {
|
|
79
|
+
updated: boolean;
|
|
80
|
+
}>;
|
|
81
|
+
cognitoSignUp: _$better_auth0.StrictEndpoint<"/cognito/sign-up", {
|
|
82
|
+
method: "POST";
|
|
83
|
+
body: _$zod.ZodObject<{
|
|
84
|
+
email: _$zod.ZodEmail;
|
|
85
|
+
password: _$zod.ZodString;
|
|
86
|
+
}, _$zod_v4_core0.$strip>;
|
|
87
|
+
}, {
|
|
88
|
+
userConfirmed: boolean | undefined;
|
|
89
|
+
userSub: string | undefined;
|
|
90
|
+
codeDeliveryDetails: _$_aws_sdk_client_cognito_identity_provider0.CodeDeliveryDetailsType | null;
|
|
91
|
+
}>;
|
|
92
|
+
cognitoConfirmSignUp: _$better_auth0.StrictEndpoint<"/cognito/confirm-sign-up", {
|
|
93
|
+
method: "POST";
|
|
94
|
+
body: _$zod.ZodObject<{
|
|
95
|
+
email: _$zod.ZodEmail;
|
|
96
|
+
code: _$zod.ZodString;
|
|
97
|
+
}, _$zod_v4_core0.$strip>;
|
|
98
|
+
}, {
|
|
99
|
+
confirmed: boolean;
|
|
100
|
+
}>;
|
|
101
|
+
cognitoResendConfirmationCode: _$better_auth0.StrictEndpoint<"/cognito/resend-confirmation", {
|
|
102
|
+
method: "POST";
|
|
103
|
+
body: _$zod.ZodObject<{
|
|
104
|
+
email: _$zod.ZodEmail;
|
|
105
|
+
}, _$zod_v4_core0.$strip>;
|
|
106
|
+
}, {
|
|
107
|
+
codeDeliveryDetails: _$_aws_sdk_client_cognito_identity_provider0.CodeDeliveryDetailsType | null;
|
|
108
|
+
}>;
|
|
109
|
+
cognitoForgotPassword: _$better_auth0.StrictEndpoint<"/cognito/forgot-password", {
|
|
110
|
+
method: "POST";
|
|
111
|
+
body: _$zod.ZodObject<{
|
|
112
|
+
email: _$zod.ZodEmail;
|
|
113
|
+
}, _$zod_v4_core0.$strip>;
|
|
114
|
+
}, {
|
|
115
|
+
codeDeliveryDetails: _$_aws_sdk_client_cognito_identity_provider0.CodeDeliveryDetailsType | null;
|
|
116
|
+
}>;
|
|
117
|
+
cognitoConfirmForgotPassword: _$better_auth0.StrictEndpoint<"/cognito/confirm-forgot-password", {
|
|
118
|
+
method: "POST";
|
|
119
|
+
body: _$zod.ZodObject<{
|
|
120
|
+
email: _$zod.ZodEmail;
|
|
121
|
+
code: _$zod.ZodString;
|
|
122
|
+
newPassword: _$zod.ZodString;
|
|
123
|
+
}, _$zod_v4_core0.$strip>;
|
|
124
|
+
}, {
|
|
125
|
+
reset: boolean;
|
|
126
|
+
}>;
|
|
127
|
+
cognitoSignIn: _$better_auth0.StrictEndpoint<"/cognito/sign-in", {
|
|
128
|
+
method: "POST";
|
|
129
|
+
body: _$zod.ZodObject<{
|
|
130
|
+
email: _$zod.ZodEmail;
|
|
131
|
+
password: _$zod.ZodString;
|
|
132
|
+
rememberMe: _$zod.ZodOptional<_$zod.ZodBoolean>;
|
|
133
|
+
}, _$zod_v4_core0.$strip>;
|
|
134
|
+
}, {
|
|
135
|
+
type: "NEW_PASSWORD_REQUIRED";
|
|
136
|
+
challengeSession: string | undefined;
|
|
137
|
+
} | {
|
|
138
|
+
ok: boolean;
|
|
139
|
+
}>;
|
|
140
|
+
cognitoNewPassword: _$better_auth0.StrictEndpoint<"/cognito/new-password", {
|
|
141
|
+
method: "POST";
|
|
142
|
+
body: _$zod.ZodObject<{
|
|
143
|
+
email: _$zod.ZodEmail;
|
|
144
|
+
newPassword: _$zod.ZodString;
|
|
145
|
+
challengeSession: _$zod.ZodString;
|
|
146
|
+
rememberMe: _$zod.ZodOptional<_$zod.ZodBoolean>;
|
|
147
|
+
}, _$zod_v4_core0.$strip>;
|
|
148
|
+
}, {
|
|
149
|
+
ok: boolean;
|
|
150
|
+
}>;
|
|
151
|
+
cognitoStartPasskeySignIn: _$better_auth0.StrictEndpoint<"/cognito/passkey/sign-in/start", {
|
|
152
|
+
method: "POST";
|
|
153
|
+
body: _$zod.ZodObject<{
|
|
154
|
+
email: _$zod.ZodEmail;
|
|
155
|
+
}, _$zod_v4_core0.$strip>;
|
|
156
|
+
}, {
|
|
157
|
+
session: string | undefined;
|
|
158
|
+
requestOptions: Record<string, unknown>;
|
|
159
|
+
}>;
|
|
160
|
+
cognitoCompletePasskeySignIn: _$better_auth0.StrictEndpoint<"/cognito/passkey/sign-in/complete", {
|
|
161
|
+
method: "POST";
|
|
162
|
+
body: _$zod.ZodObject<{
|
|
163
|
+
email: _$zod.ZodEmail;
|
|
164
|
+
credential: _$zod.ZodRecord<_$zod.ZodString, _$zod.ZodUnknown>;
|
|
165
|
+
session: _$zod.ZodString;
|
|
166
|
+
rememberMe: _$zod.ZodOptional<_$zod.ZodBoolean>;
|
|
167
|
+
}, _$zod_v4_core0.$strip>;
|
|
168
|
+
}, {
|
|
169
|
+
redirect: boolean;
|
|
170
|
+
token: string;
|
|
171
|
+
user: {
|
|
172
|
+
id: string;
|
|
173
|
+
createdAt: Date;
|
|
174
|
+
updatedAt: Date;
|
|
175
|
+
email: string;
|
|
176
|
+
emailVerified: boolean;
|
|
177
|
+
name: string;
|
|
178
|
+
image?: string | null | undefined;
|
|
179
|
+
} & Record<string, any>;
|
|
180
|
+
}>;
|
|
181
|
+
cognitoStartPasskeyRegistration: _$better_auth0.StrictEndpoint<"/cognito/passkey/register/start", {
|
|
182
|
+
method: "POST";
|
|
183
|
+
body: _$zod.ZodObject<{}, _$zod_v4_core0.$strip>;
|
|
184
|
+
}, {
|
|
185
|
+
credentialCreationOptions: _$_smithy_types0.DocumentType | undefined;
|
|
186
|
+
}>;
|
|
187
|
+
cognitoCompletePasskeyRegistration: _$better_auth0.StrictEndpoint<"/cognito/passkey/register/complete", {
|
|
188
|
+
method: "POST";
|
|
189
|
+
body: _$zod.ZodObject<{
|
|
190
|
+
credential: _$zod.ZodRecord<_$zod.ZodString, _$zod.ZodUnknown>;
|
|
191
|
+
}, _$zod_v4_core0.$strip>;
|
|
192
|
+
}, {
|
|
193
|
+
ok: boolean;
|
|
194
|
+
}>;
|
|
195
|
+
cognitoSignOut: _$better_auth0.StrictEndpoint<"/cognito/sign-out", {
|
|
196
|
+
method: "POST";
|
|
197
|
+
body: _$zod.ZodOptional<_$zod.ZodObject<{
|
|
198
|
+
redirectTo: _$zod.ZodOptional<_$zod.ZodString>;
|
|
199
|
+
}, _$zod_v4_core0.$strip>>;
|
|
200
|
+
}, {
|
|
201
|
+
success: boolean;
|
|
202
|
+
}>;
|
|
203
|
+
};
|
|
204
|
+
$ERROR_CODES: Record<string, {
|
|
205
|
+
code: string;
|
|
206
|
+
message: string;
|
|
207
|
+
}>;
|
|
208
|
+
options: CognitoPluginOptions;
|
|
209
|
+
};
|
|
210
|
+
/** Globally sign out from Cognito (invalidates the refresh token). Best-effort. */
|
|
211
|
+
declare function cognitoGlobalSignOut(accessToken: string, opts: Pick<CognitoPluginOptions, "region">): Promise<void>;
|
|
212
|
+
//#endregion
|
|
213
|
+
export { cognitoPlugin as n, COGNITO_ERROR_CODES as r, cognitoGlobalSignOut as t };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { i as CognitoPluginOptions, n as PasskeyMode, r as getPasskeyConfig, t as CognitoPasskeyConfig } from "./config-C3_h3skc.mjs";
|
|
2
|
+
import { n as cognitoPlugin, r as COGNITO_ERROR_CODES, t as cognitoGlobalSignOut } from "./index-D4C-gqBy.mjs";
|
|
3
|
+
export { COGNITO_ERROR_CODES, CognitoPasskeyConfig, CognitoPluginOptions, PasskeyMode, cognitoGlobalSignOut, cognitoPlugin, getPasskeyConfig };
|