Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/endpoints/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,19 @@ export function createSetupHandler(
return Response.json({ error: 'Unauthorized' }, { status: 401 })
}

const user = req.user as UserWith2FA
const user = (await req.payload.findByID({
collection: pluginConfig.collection as CollectionSlug,
id: req.user.id,
overrideAccess: true,
})) as UserWith2FA

if (user.twoFactorEnabled === true) {
return Response.json(
{ error: '2FA is already enabled for this account.' },
{ status: 409 },
)
}

const totp = createTOTPService(pluginConfig.encryptionKey)

const secret = totp.generateSecret()
Expand Down
13 changes: 12 additions & 1 deletion src/endpoints/verify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,20 @@ export function createVerifyHandler(

const totp = createTOTPService(pluginConfig.encryptionKey)
const totpWindow = pluginConfig.totp.window
const user = req.user as UserWith2FA
const user = (await req.payload.findByID({
collection: pluginConfig.collection as CollectionSlug,
id: req.user.id,
overrideAccess: true,
})) as UserWith2FA

if (action === 'enable') {
if (user.twoFactorEnabled === true) {
return Response.json(
{ error: '2FA is already enabled for this account.' },
{ status: 409 },
)
}

const encryptedPending = user.twoFactorPending

if (!encryptedPending) {
Expand Down
Loading