Skip to content

Commit

Permalink
Update auth integration
Browse files Browse the repository at this point in the history
  • Loading branch information
lcharette committed Jul 14, 2024
1 parent 54fa1b0 commit 5f13171
Show file tree
Hide file tree
Showing 9 changed files with 164 additions and 200 deletions.
7 changes: 2 additions & 5 deletions app/assets/components/Auth/AuthCheck.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
<script setup>
import { useAuthStore } from '@userfrosting/sprinkle-account/stores'
import { useCheckApi } from '@userfrosting/sprinkle-account/api'
const auth = useAuthStore()
// Login API variables
const { loading, check } = useCheckApi(auth)
check()
auth.check()
</script>

<template>
Expand All @@ -26,7 +23,7 @@ check()
</span>
</p>
<p>
<button class="uk-button uk-button-primary" @click="check()" :disabled="loading">
<button class="uk-button uk-button-primary" @click="auth.check()" :disabled="auth.loading">
Check Authentication
</button>
</p>
Expand Down
52 changes: 0 additions & 52 deletions app/assets/components/Auth/AuthLogin.vue

This file was deleted.

6 changes: 1 addition & 5 deletions app/assets/components/Auth/AuthLogout.vue
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
<script setup>
import { useLogoutApi } from '@userfrosting/sprinkle-account/api'
import { useAuthStore } from '@userfrosting/sprinkle-account/stores'
// Logout API variables
const auth = useAuthStore()
const { loading, logout } = useLogoutApi(auth)
</script>

<template>
<div class="uk-margin uk-text-center">
<button class="uk-button uk-button-default" @click="logout()" :disabled="loading">
<button class="uk-button uk-button-default" @click="auth.logout()" :disabled="auth.loading">
Logout
</button>
</div>
Expand Down
7 changes: 4 additions & 3 deletions app/assets/components/NavBar.vue
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
<script setup>
import { useLogoutApi } from '@userfrosting/sprinkle-account/api'
import { useAuthStore } from '@userfrosting/sprinkle-account/stores'
// Logout API variables
const auth = useAuthStore()
const { logout } = useLogoutApi(auth)
auth.check() // TODO : Move to main.ts ?
</script>

<template>
<UFNavBar title="Userfrosting">
<UFNavBarItem :to="{ name: 'home' }" label="Home" />
<UFNavBarItem :to="{ name: 'about' }" label="About" />
<UFNavBarItem :to="{ name: 'auth' }" label="Auth" />
<UFNavBarItem :to="{ name: 'login' }" label="Login" />
<UFNavBarLogin v-if="!auth.isAuthenticated" />
<UFNavBarUserCard
v-if="auth.isAuthenticated"
:username="auth.user.full_name"
:avatar="auth.user.avatar"
:meta="auth.user.user_name">
<UFNavBarUserCardButton label="Logout" @click="logout()" />
<UFNavBarUserCardButton label="Logout" @click="auth.logout()" />
</UFNavBarUserCard>
</UFNavBar>
</template>
12 changes: 12 additions & 0 deletions app/assets/router/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createRouter, createWebHistory } from 'vue-router'
import { useAuthStore } from '@userfrosting/sprinkle-account/stores'

const router = createRouter({
history: createWebHistory(),
Expand All @@ -22,6 +23,17 @@ const router = createRouter({
path: '/auth',
name: 'auth',
component: () => import('../views/AuthView.vue')
},
{
path: '/login',
name: 'login',
component: () => import('../views/LoginView.vue'),
beforeEnter: () => {
const auth = useAuthStore()
if (auth.isAuthenticated) {
return { name: 'home' }
}
}
}
]
}
Expand Down
3 changes: 1 addition & 2 deletions app/assets/views/AuthView.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<script setup>
import AuthCheck from '../components/Auth/AuthCheck.vue'
import Login from '../components/Auth/AuthLogin.vue'
import Logout from '../components/Auth/AuthLogout.vue'
import { useAuthStore } from '@userfrosting/sprinkle-account/stores'
const auth = useAuthStore()
Expand All @@ -13,7 +12,7 @@ const auth = useAuthStore()
<Logout />
</div>
<div v-else>
<Login />
<UFFormLogin />
</div>
<div>
<AuthCheck />
Expand Down
3 changes: 3 additions & 0 deletions app/assets/views/LoginView.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<UFPageLogin />
</template>
Loading

0 comments on commit 5f13171

Please sign in to comment.