Skip to content

Commit

Permalink
feat(frontend): add logout btn, improve login flow
Browse files Browse the repository at this point in the history
  • Loading branch information
KeziahMoselle committed Apr 7, 2024
1 parent 8c6e26c commit 2eaec54
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
3 changes: 3 additions & 0 deletions frontend/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export async function login(payload: ILoginPayload) {
loading: 'Logging in...',
success(response) {
isSuccess = true
location.href = '/'
// @ts-ignore
return `Welcome ${response.user.name}!`
},
Expand Down Expand Up @@ -83,6 +84,7 @@ export async function register(payload: IRegisterPayload) {
loading: 'Creating your account...',
success() {
isSuccess = true
location.href = '/login'
return `Successfully registered!`
},
error: (error) => {
Expand All @@ -102,6 +104,7 @@ export async function logout() {
toast.promise(logout, {
loading: 'Loading...',
success() {
location.href = '/'
return `You have been logged out.`
},
error: () => {
Expand Down
9 changes: 9 additions & 0 deletions frontend/src/components/Auth/Logout.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<script setup lang="ts">
import { logout } from '@/api';
</script>

<template>
<button @click="logout" class="button" type="button">
Logout
</button>
</template>
2 changes: 1 addition & 1 deletion frontend/src/components/EldenRing/Builder.vue
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ const onSubmit = handleSubmit((values) => {
</div>
</div>

<div class="flex justify-center mt-12">
<div class="flex justify-center my-12">
<button class="button" type="submit">
Create
</button>
Expand Down
8 changes: 7 additions & 1 deletion frontend/src/layouts/Layout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import '@/styles/globals.scss'
import { Toaster } from 'vue-sonner'
import { SquareMenu } from 'lucide-vue-next'
import Logout from '@/components/Auth/Logout.vue'
interface Props {
title: string;
Expand Down Expand Up @@ -34,7 +35,12 @@ const { user } = Astro.locals;
</picture>
</a>

{user && <h1>Welcome {user.name}!</h1>}
{user && (
<div class="flex gap-x-4 items-center">
<h1>Welcome {user.name}!</h1>
<Logout client:visible />
</div>
)}
</div>

<!-- Desktop nav -->
Expand Down

0 comments on commit 2eaec54

Please sign in to comment.