-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: shop dashboard is behind login (#62)
- Loading branch information
Showing
21 changed files
with
284 additions
and
130 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,6 @@ | ||
export default () => ({}); | ||
export default () => ({ | ||
'config-sync': { | ||
enabled: true, | ||
importOnBootstrap: true, | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export default defineNuxtRouteMiddleware((to) => { | ||
const authenticated = useState('authenticated', () => false); | ||
const token = useCookie('token'); // get token from cookies | ||
if (token.value) { | ||
// check if value exists | ||
authenticated.value = true; // update the state to authenticated | ||
} | ||
// if token exists and url is /login redirect to homepage | ||
if (token.value && to?.name === 'login') { | ||
return navigateTo('/shop'); | ||
} | ||
// if token doesn't exist redirect to log in | ||
if (!token.value && to?.name !== 'shop/login') { | ||
abortNavigation(); | ||
return navigateTo('/shop/login'); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<template> | ||
<main class="form-signin"> | ||
<form> | ||
<h1 class="h3 mb-3 fw-normal">Fai il login per entrare nell'area riservata</h1> | ||
<div class="form-floating"> | ||
<input type="email" class="form-control" id="floatingInput" placeholder="[email protected]" | ||
v-model="username"> | ||
<label for="floatingInput">Email address</label> | ||
</div> | ||
<div class="form-floating"> | ||
<input type="password" class="form-control" id="floatingPassword" placeholder="Password" | ||
v-model="password"> | ||
<label for="floatingPassword">Password</label> | ||
</div> | ||
|
||
<button class="w-100 btn btn-lg btn-primary" @click.prevent="login">Sign in</button> | ||
</form> | ||
</main> | ||
</template> | ||
|
||
<script lang="ts"> | ||
export default { | ||
data() { | ||
return { | ||
username: "", | ||
password: "" | ||
} | ||
}, | ||
methods: { | ||
async login() { | ||
const authenticated = useState('authenticated', () => false); | ||
const token = useCookie('token'); | ||
const user = useCookie('user'); | ||
let response = await this.$backend.auth.login(this.username, this.password); | ||
if (response.ok) { | ||
token.value = response.val.jwt; | ||
user.value = response.val.user; | ||
navigateTo("/shop") | ||
} else { | ||
this.$toast.error("C'è stato un errore nel login") | ||
} | ||
} | ||
} | ||
}</script> | ||
<style> | ||
.form-signin { | ||
width: 100%; | ||
max-width: 330px; | ||
padding: 15px; | ||
margin: auto; | ||
} | ||
.form-signin .checkbox { | ||
font-weight: 400; | ||
} | ||
.form-signin .form-floating:focus-within { | ||
z-index: 2; | ||
} | ||
.form-signin input[type="email"] { | ||
margin-bottom: -1px; | ||
border-bottom-right-radius: 0; | ||
border-bottom-left-radius: 0; | ||
} | ||
.form-signin input[type="password"] { | ||
margin-bottom: 10px; | ||
border-top-left-radius: 0; | ||
border-top-right-radius: 0; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.