fix: 2fa not working
This commit is contained in:
1 parent
3275dc6f94
commit
daa124a51e
2 files changed
+23
-33
No files matched your search
+1
-1
@@ -16,7 +16,7 @@ type Feature = keyof typeof FEATURES
|
|||||||
export const feature = (feature: Feature, version: string = '0.0.0'): boolean =>
|
export const feature = (feature: Feature, version: string = '0.0.0'): boolean =>
|
||||||
versionIsSupported(version, FEATURES[feature])
|
versionIsSupported(version, FEATURES[feature])
|
||||||
|
|
||||||
export const MINIMUM_VERSION = '0.18.1'
|
export const MINIMUM_VERSION = '0.19.0'
|
||||||
export const MAXIMUM_VERSION = '0.999'
|
export const MAXIMUM_VERSION = '0.999'
|
||||||
|
|
||||||
export const versionIsSupported = (v: string, minimum: string) => {
|
export const versionIsSupported = (v: string, minimum: string) => {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
import { ClipboardDocument, Icon } from 'svelte-hero-icons'
|
import { ClipboardDocument, Icon } from 'svelte-hero-icons'
|
||||||
import { goto } from '$app/navigation'
|
import { goto } from '$app/navigation'
|
||||||
import { page } from '$app/stores'
|
import { page } from '$app/stores'
|
||||||
|
import Switch from '$lib/components/input/Switch.svelte'
|
||||||
import { feature } from '$lib/version.js'
|
import { feature } from '$lib/version.js'
|
||||||
|
|
||||||
export let data
|
export let data
|
||||||
@@ -58,29 +59,23 @@
|
|||||||
if (!$profile?.jwt) return
|
if (!$profile?.jwt) return
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (feature('newTotp', $site?.version)) {
|
if (update) {
|
||||||
if (update) {
|
await getClient().updateTotp({
|
||||||
await getClient().updateTotp({
|
enabled: enabled,
|
||||||
enabled: enabled,
|
totp_token: verify_totp,
|
||||||
totp_token: verify_totp,
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
const res = await getClient().generateTotpSecret()
|
|
||||||
totpLink = res.totp_secret_url
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
const res = await getClient().saveUserSettings({
|
|
||||||
...data.my_user?.local_user_view.local_user,
|
|
||||||
...data.my_user?.local_user_view.person,
|
|
||||||
// @ts-ignore
|
|
||||||
generate_totp_2fa: enabled,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
toast({
|
||||||
|
content: `2FA has been ${enabled ? 'enabled' : 'disabled'}`,
|
||||||
|
type: 'success',
|
||||||
|
})
|
||||||
|
|
||||||
|
goto($page.url, { invalidateAll: true })
|
||||||
|
} else {
|
||||||
|
const res = await getClient().generateTotpSecret()
|
||||||
|
totpLink = res.totp_secret_url
|
||||||
|
totpEnabled = true
|
||||||
}
|
}
|
||||||
goto($page.url, { invalidateAll: true })
|
|
||||||
toast({
|
|
||||||
content: `Successfully ${enabled ? 'enabled' : 'disabled'} 2FA.`,
|
|
||||||
type: 'success',
|
|
||||||
})
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
toast({ content: e as any, type: 'error' })
|
toast({ content: e as any, type: 'error' })
|
||||||
}
|
}
|
||||||
@@ -118,19 +113,15 @@
|
|||||||
</Button>
|
</Button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex flex-col gap-2 max-w-sm w-full">
|
<div class="flex flex-col gap-4 max-w-sm w-full">
|
||||||
<h1 class="font-bold text-2xl">2FA</h1>
|
<h1 class="font-bold text-2xl">2FA</h1>
|
||||||
<p>
|
<p>
|
||||||
2FA on Lemmy is unstable and you may lock yourself out of your account.
|
2FA is <span class="font-bold">
|
||||||
{#if feature('newTotp', $site?.version)}
|
{totpEnabled ? 'enabled' : 'disabled'}
|
||||||
<strong>
|
</span>
|
||||||
You cannot disable 2FA if you lose access to your authenticator.
|
|
||||||
</strong>
|
|
||||||
{/if}
|
|
||||||
</p>
|
</p>
|
||||||
{#if totpEnabled}
|
{#if totpEnabled || totpLink}
|
||||||
<!--v0.18.0 2FA: Shows a TOTP code which you copy-->
|
{#if totpLink && !totpEnabled}
|
||||||
{#if totpLink}
|
|
||||||
<TextInput disabled type="password" value={totpLink} label="TOTP Link">
|
<TextInput disabled type="password" value={totpLink} label="TOTP Link">
|
||||||
<button
|
<button
|
||||||
slot="suffix"
|
slot="suffix"
|
||||||
@@ -148,7 +139,6 @@
|
|||||||
</span>
|
</span>
|
||||||
</TextInput>
|
</TextInput>
|
||||||
{/if}
|
{/if}
|
||||||
<p>To change your 2FA state, enter your code here.</p>
|
|
||||||
<form class="flex flex-col gap-2" on:submit|preventDefault={() => {}}>
|
<form class="flex flex-col gap-2" on:submit|preventDefault={() => {}}>
|
||||||
<TextInput
|
<TextInput
|
||||||
bind:value={verify_totp}
|
bind:value={verify_totp}
|
||||||
|
|||||||
Reference in new issue
Block a user