Login updated
This commit is contained in:
@@ -29,7 +29,7 @@
|
|||||||
</v-btn>
|
</v-btn>
|
||||||
|
|
||||||
<v-btn
|
<v-btn
|
||||||
v-if="!token"
|
v-if="!isLoggedIn"
|
||||||
to="/login"
|
to="/login"
|
||||||
variant="text"
|
variant="text"
|
||||||
class="nav-auth-btn ml-4"
|
class="nav-auth-btn ml-4"
|
||||||
@@ -58,11 +58,18 @@
|
|||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import '@/assets/css/app-theme.css'
|
import '@/assets/css/app-theme.css'
|
||||||
|
const isLoggedIn = useState('isLoggedIn', () => false)
|
||||||
|
const tokenCookie = useCookie('seasoned_token')
|
||||||
|
|
||||||
const token = useCookie('seasoned_token')
|
onMounted(() => {
|
||||||
|
if (tokenCookie.value) {
|
||||||
|
isLoggedIn.value = true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
const logout = () => {
|
const logout = () => {
|
||||||
token.value = null
|
tokenCookie.value = null
|
||||||
|
isLoggedIn.value = false
|
||||||
|
|
||||||
if (import.meta.client) {
|
if (import.meta.client) {
|
||||||
localStorage.removeItem('token')
|
localStorage.removeItem('token')
|
||||||
|
|||||||
@@ -114,11 +114,41 @@ const handleAuth = async () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
if (isLogin.value) {
|
if (isLogin.value) {
|
||||||
navigateTo('/gallery')
|
const isLoggedIn = useState('isLoggedIn')
|
||||||
|
isLoggedIn.value = true
|
||||||
|
snackbar.value = {
|
||||||
|
show: true,
|
||||||
|
message: 'Welcome back!',
|
||||||
|
color: '#f4ede1',
|
||||||
|
icon: 'mdi-account-check',
|
||||||
|
iconColor: '#556b2f',
|
||||||
|
textColor: '#5d4037'
|
||||||
|
}
|
||||||
|
setTimeout(() => {
|
||||||
|
navigateTo('/')
|
||||||
|
}, 1200)
|
||||||
|
} else {
|
||||||
|
snackbar.value = {
|
||||||
|
show: true,
|
||||||
|
message: 'Account created! Try signing in.',
|
||||||
|
color: '#f4ede1',
|
||||||
|
icon: 'mdi-feather',
|
||||||
|
iconColor: '#556b2f',
|
||||||
|
textColor: '#5d4037'
|
||||||
|
}
|
||||||
|
isLogin.value = true
|
||||||
|
authLoading.value = false
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
alert("Authentication failed. Check your credentials.")
|
authLoading.value = false
|
||||||
|
snackbar.value = {
|
||||||
|
show: true,
|
||||||
|
message: 'The archives do not recognize these credentials.',
|
||||||
|
color: '#efe5e3',
|
||||||
|
icon: 'mdi-alert-rhombus',
|
||||||
|
iconColor: '#8c4a32',
|
||||||
|
textColor: '#5d4037'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
Reference in New Issue
Block a user