fix: make password changing actually work
This commit is contained in:
1 parent
76f22dab5c
commit
ac147086f1
4 files changed
+24
-19
No files matched your search
@@ -227,19 +227,6 @@ instance.subscribe(async (i) => {
|
||||
} catch (e) {}
|
||||
})
|
||||
|
||||
export function updateJwt(id: number, newJwt: string) {
|
||||
const pd = get(profileData)
|
||||
let prof = pd.profiles.find((p) => p.id == id)
|
||||
|
||||
if (!prof) return
|
||||
prof = serializeUser(prof)
|
||||
prof.jwt = newJwt
|
||||
|
||||
profileData.update((p) => ({ ...p, profile: id }))
|
||||
|
||||
profile.update(() => prof)
|
||||
}
|
||||
|
||||
export async function setUserID(id: number) {
|
||||
const pd = get(profileData)
|
||||
if (id == -1) {
|
||||
|
||||
@@ -128,6 +128,16 @@
|
||||
<Checkbox bind:checked={formData.federation_enabled} defaultValue={true}>
|
||||
Federation enabled
|
||||
</Checkbox>
|
||||
<Checkbox bind:checked={formData.federation_debug} defaultValue={false}>
|
||||
Federation debug mode
|
||||
</Checkbox>
|
||||
<Checkbox bind:checked={formData.captcha_enabled} defaultValue={false}>
|
||||
Captcha enabled
|
||||
</Checkbox>
|
||||
{#if formData.captcha_enabled}
|
||||
{console.log(formData.captcha_difficulty)}
|
||||
<Select bind:value={formData.captcha_difficulty} />
|
||||
{/if}
|
||||
{/if}
|
||||
<Button color="primary" size="lg" loading={saving} disabled={saving} submit>
|
||||
Save
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
<script lang="ts">
|
||||
import { goto } from '$app/navigation'
|
||||
import { setUser } from '$lib/auth.js'
|
||||
import Link from '$lib/components/input/Link.svelte'
|
||||
import { Material, toast } from 'mono-svelte'
|
||||
import { toast } from 'mono-svelte'
|
||||
import { DEFAULT_INSTANCE_URL, LINKED_INSTANCE_URL } from '$lib/instance.js'
|
||||
import { getClient, validateInstance } from '$lib/lemmy.js'
|
||||
import { Button, TextInput } from 'mono-svelte'
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
<script lang="ts">
|
||||
import { profile, setUser, setUserID, updateJwt } from '$lib/auth.js'
|
||||
import { deleteProfile, profile, setUser } from '$lib/auth.js'
|
||||
import { getClient } from '$lib/lemmy.js'
|
||||
import { trycatch } from '$lib/util.js'
|
||||
import { Button, TextInput, toast } from 'mono-svelte'
|
||||
import { instance as currentInstance } from '$lib/instance.js'
|
||||
|
||||
let oldPassword = '',
|
||||
newPassword = '',
|
||||
newPasswordVerify = ''
|
||||
let loading = false
|
||||
|
||||
async function submit() {
|
||||
loading = true
|
||||
const res = await trycatch(async () => {
|
||||
if (!$profile?.jwt) return
|
||||
const res = await getClient().changePassword({
|
||||
@@ -18,8 +21,10 @@
|
||||
old_password: oldPassword,
|
||||
})
|
||||
if (res?.jwt) {
|
||||
updateJwt($profile.id, res.jwt)
|
||||
await setUserID($profile.id)
|
||||
const { instance, username } = $profile
|
||||
deleteProfile($profile.id)
|
||||
await setUser(res.jwt, instance, username!)
|
||||
$currentInstance = instance
|
||||
|
||||
toast({ content: 'Your login was refreshed.', type: 'success' })
|
||||
} else {
|
||||
@@ -28,6 +33,8 @@
|
||||
})
|
||||
|
||||
if (res) toast({ content: 'Successfully changed your password. ' })
|
||||
|
||||
loading = false
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -51,5 +58,7 @@
|
||||
type="password"
|
||||
required
|
||||
/>
|
||||
<Button size="lg" color="primary" submit>Submit</Button>
|
||||
<Button size="lg" color="primary" submit {loading} disabled={loading}>
|
||||
Submit
|
||||
</Button>
|
||||
</form>
|
||||
Reference in new issue
Block a user