feat: improved auth form status messages

This commit is contained in:
ae 2025-05-05 10:44:00 +03:00
parent 0ef65937e8
commit 99b515d1d1
Signed by: ae
GPG Key ID: 995EFD5C1B532B3E
3 changed files with 9 additions and 4 deletions

View File

@ -1,5 +1,5 @@
<script lang="ts">
import { cError } from "$lib/logic/client"
import { cError, cSuccess } from "$lib/logic/client"
import { onMount } from "svelte"
import ThemeToggle from "./ThemeToggle.svelte"
import { isPasswordValid, isUsernameValid } from "$lib/util/authValidation"
@ -75,6 +75,10 @@
<div class="error max-w-full overflow-hidden text-ellipsis text-center">
{$cError}
</div>
{:else if $cSuccess}
<div class="success max-w-full overflow-hidden text-ellipsis text-center">
{$cSuccess}
</div>
{/if}
{#if !ACCOUNT_CREATION_ENABLED && formName === "Register"}

View File

@ -36,7 +36,7 @@
onMount(async (): Promise<any> => {
// the following fetch attempts to refresh any expired tokens automatically
await apiClient.getCurrentUser()
await apiClient.getUserCheckAuth()
// if still no current user after the fetch attempt, redirect to login
if (!$currentUser) {

View File

@ -294,6 +294,7 @@ class ApiClient {
}>(response, { useBearerAuth: false })
console.log(`[USER] Registration of user '${data.username}' successful`)
cSuccess.set(`User created successfully.`)
await goto("/login")
},
@ -348,7 +349,7 @@ class ApiClient {
)
}
public async getCurrentUser(): Promise<void | null> {
public async getUserCheckAuth(): Promise<void | null> {
return this.handleRequest(
async () => {
const response = await fetch(`${this.baseUrl}/auth/me`, {
@ -361,7 +362,7 @@ class ApiClient {
currentUser.set(user)
},
{ useBearerAuth: true, suspendGlobalErr: false }
{ useBearerAuth: true, suspendGlobalErr: true }
)
}