@delmaredigital/payload-better-auth 0.7.2 → 0.7.4
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.
|
@@ -17,6 +17,7 @@ import { createPayloadAuthClient } from '../../exports/client.js';
|
|
|
17
17
|
const [backupCodes, setBackupCodes] = useState([]);
|
|
18
18
|
const [verificationCode, setVerificationCode] = useState('');
|
|
19
19
|
const [password, setPassword] = useState('');
|
|
20
|
+
const [passwordAction, setPasswordAction] = useState('enable');
|
|
20
21
|
const [actionLoading, setActionLoading] = useState(false);
|
|
21
22
|
const getClient = ()=>providedClient ?? createPayloadAuthClient();
|
|
22
23
|
useEffect(()=>{
|
|
@@ -41,10 +42,18 @@ import { createPayloadAuthClient } from '../../exports/client.js';
|
|
|
41
42
|
}
|
|
42
43
|
function handleEnableClick() {
|
|
43
44
|
// Show password prompt first
|
|
45
|
+
setPasswordAction('enable');
|
|
44
46
|
setStep('password');
|
|
45
47
|
setPassword('');
|
|
46
48
|
setError(null);
|
|
47
49
|
}
|
|
50
|
+
function handlePasswordContinue() {
|
|
51
|
+
if (passwordAction === 'disable') {
|
|
52
|
+
void handleDisableWithPassword();
|
|
53
|
+
} else {
|
|
54
|
+
void handleEnableWithPassword();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
48
57
|
async function handleEnableWithPassword() {
|
|
49
58
|
setActionLoading(true);
|
|
50
59
|
setError(null);
|
|
@@ -95,21 +104,32 @@ import { createPayloadAuthClient } from '../../exports/client.js';
|
|
|
95
104
|
setActionLoading(false);
|
|
96
105
|
}
|
|
97
106
|
}
|
|
98
|
-
|
|
107
|
+
function handleDisableClick() {
|
|
99
108
|
if (!confirm('Are you sure you want to disable two-factor authentication?')) {
|
|
100
109
|
return;
|
|
101
110
|
}
|
|
111
|
+
// Better Auth's /two-factor/disable requires the account password.
|
|
112
|
+
// Prompt for it instead of sending an empty string (which fails with
|
|
113
|
+
// "Invalid password" before the real password is ever checked).
|
|
114
|
+
setPasswordAction('disable');
|
|
115
|
+
setStep('password');
|
|
116
|
+
setPassword('');
|
|
117
|
+
setError(null);
|
|
118
|
+
}
|
|
119
|
+
async function handleDisableWithPassword() {
|
|
102
120
|
setActionLoading(true);
|
|
103
121
|
setError(null);
|
|
104
122
|
try {
|
|
105
123
|
const client = getClient();
|
|
106
124
|
const result = await client.twoFactor.disable({
|
|
107
|
-
password
|
|
125
|
+
password
|
|
108
126
|
});
|
|
109
127
|
if (result.error) {
|
|
110
128
|
setError(result.error.message ?? 'Failed to disable 2FA');
|
|
111
129
|
} else {
|
|
112
130
|
setIsEnabled(false);
|
|
131
|
+
setPassword('');
|
|
132
|
+
setStep('status');
|
|
113
133
|
onComplete?.();
|
|
114
134
|
}
|
|
115
135
|
} catch {
|
|
@@ -153,7 +173,7 @@ import { createPayloadAuthClient } from '../../exports/client.js';
|
|
|
153
173
|
/*#__PURE__*/ _jsx(Button, {
|
|
154
174
|
buttonStyle: isEnabled ? 'error' : 'secondary',
|
|
155
175
|
size: "small",
|
|
156
|
-
onClick: isEnabled ?
|
|
176
|
+
onClick: isEnabled ? handleDisableClick : handleEnableClick,
|
|
157
177
|
disabled: actionLoading,
|
|
158
178
|
children: actionLoading ? 'Loading...' : isEnabled ? 'Disable' : 'Enable'
|
|
159
179
|
})
|
|
@@ -161,9 +181,13 @@ import { createPayloadAuthClient } from '../../exports/client.js';
|
|
|
161
181
|
}),
|
|
162
182
|
step === 'password' && /*#__PURE__*/ _jsxs("div", {
|
|
163
183
|
children: [
|
|
164
|
-
/*#__PURE__*/
|
|
184
|
+
/*#__PURE__*/ _jsxs("p", {
|
|
165
185
|
className: "field-description",
|
|
166
|
-
children:
|
|
186
|
+
children: [
|
|
187
|
+
"Enter your password to ",
|
|
188
|
+
passwordAction === 'disable' ? 'disable' : 'enable',
|
|
189
|
+
" two-factor authentication."
|
|
190
|
+
]
|
|
167
191
|
}),
|
|
168
192
|
/*#__PURE__*/ _jsx("input", {
|
|
169
193
|
type: "password",
|
|
@@ -172,7 +196,7 @@ import { createPayloadAuthClient } from '../../exports/client.js';
|
|
|
172
196
|
onKeyDown: (e)=>{
|
|
173
197
|
if (e.key === 'Enter' && password) {
|
|
174
198
|
e.preventDefault();
|
|
175
|
-
|
|
199
|
+
handlePasswordContinue();
|
|
176
200
|
}
|
|
177
201
|
},
|
|
178
202
|
placeholder: "Enter your password",
|
|
@@ -198,9 +222,9 @@ import { createPayloadAuthClient } from '../../exports/client.js';
|
|
|
198
222
|
/*#__PURE__*/ _jsx(Button, {
|
|
199
223
|
buttonStyle: "primary",
|
|
200
224
|
size: "small",
|
|
201
|
-
onClick:
|
|
225
|
+
onClick: handlePasswordContinue,
|
|
202
226
|
disabled: actionLoading || !password,
|
|
203
|
-
children: actionLoading ? 'Enabling...' : 'Continue'
|
|
227
|
+
children: actionLoading ? passwordAction === 'disable' ? 'Disabling...' : 'Enabling...' : 'Continue'
|
|
204
228
|
}),
|
|
205
229
|
/*#__PURE__*/ _jsx(Button, {
|
|
206
230
|
buttonStyle: "secondary",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@delmaredigital/payload-better-auth",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.4",
|
|
4
4
|
"description": "Better Auth adapter and plugins for Payload CMS",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -116,8 +116,8 @@
|
|
|
116
116
|
"@better-auth/api-key": "^1.6.10",
|
|
117
117
|
"@better-auth/oauth-provider": "^1.6.10",
|
|
118
118
|
"@better-auth/passkey": "^1.6.10",
|
|
119
|
-
"@payloadcms/next": "^3.
|
|
120
|
-
"@payloadcms/ui": "^3.
|
|
119
|
+
"@payloadcms/next": "^3.84.1",
|
|
120
|
+
"@payloadcms/ui": "^3.84.1",
|
|
121
121
|
"@swc/cli": "^0.6.0",
|
|
122
122
|
"@swc/core": "^1.15.30",
|
|
123
123
|
"@types/node": "^24.12.2",
|
|
@@ -125,7 +125,7 @@
|
|
|
125
125
|
"@vitest/coverage-v8": "^2.1.9",
|
|
126
126
|
"better-auth": "^1.6.10",
|
|
127
127
|
"next": "^16.2.5",
|
|
128
|
-
"payload": "^3.
|
|
128
|
+
"payload": "^3.84.1",
|
|
129
129
|
"react": "^19.2.5",
|
|
130
130
|
"tsx": "^4.21.0",
|
|
131
131
|
"typescript": "^5.9.3",
|