Skip to content

Commit

Permalink
feat: shop dashboard is behind login (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
alcaprar authored Aug 3, 2024
1 parent b520001 commit bc9c7a5
Show file tree
Hide file tree
Showing 21 changed files with 284 additions and 130 deletions.
Binary file modified backend/.tmp/dev.data.db
Binary file not shown.
7 changes: 6 additions & 1 deletion backend/config/plugins.ts
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
export default () => ({});
export default () => ({
'config-sync': {
enabled: true,
importOnBootstrap: true,
}
});
46 changes: 44 additions & 2 deletions backend/config/sync/user-role.authenticated.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,52 @@
"type": "authenticated",
"permissions": [
{
"action": "api::order-item.order-item.increment"
"action": "api::client.client.create"
},
{
"action": "api::order.order.updateNotes"
"action": "api::order.order.find"
},
{
"action": "api::product-sale.product-sale.updateAmount"
},
{
"action": "api::product-sale.product-sale.updateTotalAvailable"
},
{
"action": "api::product.product.create"
},
{
"action": "api::product.product.findOne"
},
{
"action": "api::sale.sale.addProduct"
},
{
"action": "api::sale.sale.create"
},
{
"action": "api::sale.sale.findOne"
},
{
"action": "api::sale.sale.getOrders"
},
{
"action": "api::sale.sale.update"
},
{
"action": "api::shop.shop.addUnit"
},
{
"action": "api::shop.shop.clients"
},
{
"action": "api::shop.shop.products"
},
{
"action": "api::shop.shop.sales"
},
{
"action": "api::shop.shop.units"
},
{
"action": "plugin::users-permissions.auth.changePassword"
Expand Down
8 changes: 1 addition & 7 deletions backend/src/api/client/routes/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,4 @@

import { factories } from '@strapi/strapi'

export default factories.createCoreRouter('api::client.client', {
config: {
create: {
auth: false
}
}
})
export default factories.createCoreRouter('api::client.client')
3 changes: 0 additions & 3 deletions backend/src/api/product/routes/product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ export default factories.createCoreRouter('api::product.product', {
create: {
auth: false
},
findOne: {
auth: false
},
update: {
auth: false
}
Expand Down
11 changes: 1 addition & 10 deletions backend/src/api/shop/routes/custom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ export default {
method: 'GET',
path: '/shops/:shop/products',
handler: 'shop.products',
config: {
auth: false
}
},
{
method: 'GET',
Expand All @@ -27,18 +24,12 @@ export default {
{
method: 'GET',
path: '/shops/:shop/units',
handler: 'shop.units',
config: {
auth: false
}
handler: 'shop.units'
},
{
method: 'POST',
path: '/shops/:shop/units',
handler: 'shop.addUnit',
config: {
auth: false
}
},
{
method: 'GET',
Expand Down
17 changes: 17 additions & 0 deletions frontend/middleware/auth.ts
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');
}
});
2 changes: 1 addition & 1 deletion frontend/pages/order/[shop]/[client].vue
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export default {
async created() {
this.$loader.startLoader();
let result = await this.$backend.clients.get(this.shopSlug, this.clientUsername);
let result = await this.$backend.clients.getByUsername(this.shopSlug, this.clientUsername);
this.$loader.stopLoader();
if (result.ok) {
if (result.ok) {
Expand Down
2 changes: 1 addition & 1 deletion frontend/pages/order/[shop]/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default {
}
},
async clientExist(clientUsername: string): Promise<boolean> {
let result = await this.$backend.clients.get(this.shopSlug, clientUsername);
let result = await this.$backend.clients.getByUsername(this.shopSlug, clientUsername);
return result.ok
},
}
Expand Down
5 changes: 4 additions & 1 deletion frontend/pages/shop/changelog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
export default {
setup() {
definePageMeta({ layout: "admin" });
definePageMeta({
layout: "admin",
middleware: "auth"
});
},
data() {
return {
Expand Down
5 changes: 4 additions & 1 deletion frontend/pages/shop/clients/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@
<script lang="ts">
export default {
setup() {
definePageMeta({ layout: "admin" });
definePageMeta({
layout: "admin",
middleware: "auth"
});
},
data() {
Expand Down
12 changes: 5 additions & 7 deletions frontend/pages/shop/index.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<template>
<div
class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom"
>
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
<h1 class="h2">Dashboard</h1>
</div>

Expand All @@ -11,10 +9,10 @@
<script lang="ts">
export default {
setup() {
definePageMeta({ layout: "admin" });
},
created() {
this.$log().info('test', this.$backend)
definePageMeta({
layout: "admin",
middleware: "auth"
});
},
};
</script>
75 changes: 75 additions & 0 deletions frontend/pages/shop/login.vue
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>
5 changes: 4 additions & 1 deletion frontend/pages/shop/orders/[order].vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@
<script lang="ts">
export default {
setup() {
definePageMeta({ layout: "admin" });
definePageMeta({
layout: "admin",
middleware: "auth"
});
},
data() {
Expand Down
5 changes: 4 additions & 1 deletion frontend/pages/shop/products/[product].vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@
<script lang="ts">
export default {
setup() {
definePageMeta({ layout: "admin" });
definePageMeta({
layout: "admin",
middleware: "auth"
});
},
data() {
return {
Expand Down
5 changes: 4 additions & 1 deletion frontend/pages/shop/products/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ import utils from "~/utils";
export default {
setup() {
definePageMeta({ layout: "admin" });
definePageMeta({
layout: "admin",
middleware: "auth"
});
},
data() {
Expand Down
5 changes: 4 additions & 1 deletion frontend/pages/shop/sales/[sale].vue
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@
export default {
setup() {
definePageMeta({ layout: "admin" });
definePageMeta({
layout: "admin",
middleware: "auth"
});
},
data() {
Expand Down
5 changes: 4 additions & 1 deletion frontend/pages/shop/sales/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@
<script lang="ts">
export default {
setup() {
definePageMeta({ layout: "admin" });
definePageMeta({
layout: "admin",
middleware: "auth"
});
},
data() {
Expand Down
5 changes: 4 additions & 1 deletion frontend/pages/shop/units/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@
<script lang="ts">
export default {
setup() {
definePageMeta({ layout: "admin" });
definePageMeta({
layout: "admin",
middleware: "auth"
});
},
data() {
Expand Down
Loading

0 comments on commit bc9c7a5

Please sign in to comment.