feat: improved auth form status messages
This commit is contained in:
parent
0ef65937e8
commit
99b515d1d1
@ -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"}
|
||||
|
@ -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) {
|
||||
|
@ -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 }
|
||||
)
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user