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

View File

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

View File

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