Refactor!: Codebase
This commit is contained in:
1
.env.development
Normal file
1
.env.development
Normal file
@@ -0,0 +1 @@
|
|||||||
|
VITE_API_URL=http://localhost:5001/api/v1
|
||||||
1
.env.production
Normal file
1
.env.production
Normal file
@@ -0,0 +1 @@
|
|||||||
|
VITE_API_URL=todo
|
||||||
@@ -118,18 +118,18 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { useAuthStore } from '@/plugins/store/authStore';
|
import { auth } from '@/stores/auth.js';
|
||||||
import { useRouter } from 'vue-router';
|
import { useRouter } from 'vue-router';
|
||||||
|
|
||||||
const authStore = useAuthStore();
|
const store = auth();
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
|
||||||
const logout = () => {
|
const logout = () => {
|
||||||
authStore.logout();
|
store.logout();
|
||||||
router.push('/login');
|
router.push('/login');
|
||||||
}
|
}
|
||||||
|
|
||||||
const user = authStore.user;
|
const user = store.user;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style src="../cssstyle/index.css"></style>
|
<style src="../cssstyle/index.css"></style>
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import 'vuetify/styles'
|
|||||||
import { createVuetify } from 'vuetify'
|
import { createVuetify } from 'vuetify'
|
||||||
import * as components from 'vuetify/components'
|
import * as components from 'vuetify/components'
|
||||||
import * as directives from 'vuetify/directives'
|
import * as directives from 'vuetify/directives'
|
||||||
import clientPlugin from './plugins/clientPlugin'
|
import clientPlugin from './plugins/api.js'
|
||||||
|
|
||||||
const vuetify = createVuetify({
|
const vuetify = createVuetify({
|
||||||
components,
|
components,
|
||||||
|
|||||||
35
src/plugins/api.js
Normal file
35
src/plugins/api.js
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
import axios from "axios";
|
||||||
|
import {inject} from "vue";
|
||||||
|
|
||||||
|
const key = Symbol("api");
|
||||||
|
|
||||||
|
export default function(app) {
|
||||||
|
if (!import.meta.env.VITE_API_URL) throw new Error("VITE_API_URL is not provided")
|
||||||
|
|
||||||
|
// You create a .env.development file and a .env file
|
||||||
|
// depending on the environment, the correct file will be used
|
||||||
|
const api = axios.create({
|
||||||
|
baseURL: import.meta.env.VITE_API_URL,
|
||||||
|
timeout: 2000,
|
||||||
|
});
|
||||||
|
|
||||||
|
const requestInterceptor = (config) => {
|
||||||
|
const token = localStorage.getItem("jwt");
|
||||||
|
if (token) config.headers["Authorization"] = `Bearer ${token}`;
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
|
api.interceptors.request.use(requestInterceptor);
|
||||||
|
|
||||||
|
// This is a local injection, to use it in your components you can do this:
|
||||||
|
// const api = inject("api")
|
||||||
|
// api.get("/some-endpoint")
|
||||||
|
app.provide(key, api)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useClient() {
|
||||||
|
const api = inject(key)
|
||||||
|
if (!api) throw new Error("api is not provided")
|
||||||
|
return api;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
import axios from "axios";
|
|
||||||
import { inject } from 'vue';
|
|
||||||
|
|
||||||
const clientKey = Symbol('client');
|
|
||||||
|
|
||||||
export default {
|
|
||||||
//todo: Need to have the baseURL in the config for later ( dev and prod env. )
|
|
||||||
install: (app) => {
|
|
||||||
const axiosInstance = axios.create({
|
|
||||||
baseURL: 'https://localhost:5001/',
|
|
||||||
timeout: 2000,
|
|
||||||
});
|
|
||||||
|
|
||||||
axiosInstance.interceptors.request.use((config) => {
|
|
||||||
const token = localStorage.getItem('jwt');
|
|
||||||
if (token) {
|
|
||||||
config.headers.Authorization = `Bearer ${token}`;
|
|
||||||
}
|
|
||||||
return config;
|
|
||||||
}, (error) => {
|
|
||||||
return Promise.reject(error);
|
|
||||||
});
|
|
||||||
|
|
||||||
app.provide(clientKey, axiosInstance);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export function useClient() {
|
|
||||||
const client = inject(clientKey);
|
|
||||||
if (!client) {
|
|
||||||
throw new Error('Axios instance is not provided');
|
|
||||||
}
|
|
||||||
return client;
|
|
||||||
}
|
|
||||||
@@ -2,7 +2,7 @@ import { defineStore } from 'pinia';
|
|||||||
|
|
||||||
const baseUrl = '/api/Users';
|
const baseUrl = '/api/Users';
|
||||||
|
|
||||||
export const useAuthStore = defineStore({
|
export const auth = defineStore({
|
||||||
id: 'auth',
|
id: 'auth',
|
||||||
state: () => ({
|
state: () => ({
|
||||||
user: null,
|
user: null,
|
||||||
@@ -26,9 +26,6 @@ export const useAuthStore = defineStore({
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new Error('Login failed.')
|
throw new Error('Login failed.')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
},
|
},
|
||||||
logout() {
|
logout() {
|
||||||
localStorage.setItem('jwt', '');
|
localStorage.setItem('jwt', '');
|
||||||
@@ -52,4 +49,4 @@ export const useAuthStore = defineStore({
|
|||||||
clearTimeout(this.refreshTokenTimeout);
|
clearTimeout(this.refreshTokenTimeout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -96,13 +96,15 @@
|
|||||||
|
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { useClient } from '@/plugins/clientPlugin';
|
import FooterLayout from '@/layouts/FooterLayout.vue';
|
||||||
import { useAuthStore } from '@/plugins/store/authStore';
|
import {auth} from '@/stores/auth.js';
|
||||||
import { ref } from 'vue';
|
import {ref} from 'vue';
|
||||||
import { useRouter } from 'vue-router';
|
import {useRouter} from 'vue-router';
|
||||||
|
import {useClient} from "@/plugins/api.js";
|
||||||
|
|
||||||
const authStore = useAuthStore();
|
const api = useClient()
|
||||||
const client = useClient();
|
|
||||||
|
const store = auth();
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
|
||||||
let user = ref({});
|
let user = ref({});
|
||||||
@@ -453,4 +455,4 @@ async function login() {
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
<v-container>
|
<v-container>
|
||||||
<v-row>
|
<v-row>
|
||||||
<v-col>
|
<v-col>
|
||||||
<v-text-field
|
<v-text-field
|
||||||
label="Montant ($)"
|
label="Montant ($)"
|
||||||
v-model="price"
|
v-model="price"
|
||||||
style="color: rgb(0, 109, 119); background-color: #f4f4f4">
|
style="color: rgb(0, 109, 119); background-color: #f4f4f4">
|
||||||
@@ -35,12 +35,12 @@
|
|||||||
</template>
|
</template>
|
||||||
</v-dialog>
|
</v-dialog>
|
||||||
</v-container>
|
</v-container>
|
||||||
|
|
||||||
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { useClient } from '@/plugins/clientPlugin';
|
import { useClient } from '@/plugins/api.js';
|
||||||
import { loadStripe } from '@stripe/stripe-js';
|
import { loadStripe } from '@stripe/stripe-js';
|
||||||
import { onMounted, ref } from "vue";
|
import { onMounted, ref } from "vue";
|
||||||
|
|
||||||
@@ -84,4 +84,4 @@ import { onMounted, ref } from "vue";
|
|||||||
await checkout.mount('#checkout');
|
await checkout.mount('#checkout');
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
<img style=" max-width: 60vh; max-height: 11vh;" src="../../../images/hutopy.png">
|
<img style=" max-width: 60vh; max-height: 11vh;" src="../../../images/hutopy.png">
|
||||||
<RouterLink :to="{ name: 'login' }">
|
<RouterLink :to="{ name: 'login' }">
|
||||||
<v-btn size="large"
|
<v-btn size="large"
|
||||||
style="margin-left: 20%; margin-top: 50%; background-color: #F4F4F4; min-width: 100px; max-width: 100;"
|
style="margin-left: 20%; margin-top: 50%; background-color: #F4F4F4; min-width: 100px; max-width: 100px;"
|
||||||
light elevation="0">
|
light elevation="0">
|
||||||
Connexion
|
Connexion
|
||||||
</v-btn>
|
</v-btn>
|
||||||
@@ -193,14 +193,14 @@
|
|||||||
<!-- Colonne de droite -->
|
<!-- Colonne de droite -->
|
||||||
<v-col cols="3">
|
<v-col cols="3">
|
||||||
<v-img src="../../../images/homepage/grinding.png"
|
<v-img src="../../../images/homepage/grinding.png"
|
||||||
style="margin-bottom: 4%; border-radius: 30px; width: 80 vw;"></v-img>
|
style="margin-bottom: 4%; border-radius: 30px; width: 80vw;"></v-img>
|
||||||
<v-img src="../../../images/homepage/girlarmy.png" style="border-radius: 30px; min-width: 250px;"></v-img>
|
<v-img src="../../../images/homepage/girlarmy.png" style="border-radius: 30px; min-width: 250px;"></v-img>
|
||||||
</v-col>
|
</v-col>
|
||||||
<v-col cols="3" style>
|
<v-col cols="3" style>
|
||||||
<v-img src="../../../images/homepage/microphone.png"
|
<v-img src="../../../images/homepage/microphone.png"
|
||||||
style="margin-bottom: 4%; border-radius: 30px; min-width: 250px; max-height: auto; height: auto;"></v-img>
|
style="margin-bottom: 4%; border-radius: 30px; min-width: 250px; max-height: auto; height: auto;"></v-img>
|
||||||
<v-img src="../../../images/homepage/girlvr.png"
|
<v-img src="../../../images/homepage/girlvr.png"
|
||||||
style="border-radius: 30px; min-width: 250pxpx; max-height: 350;"></v-img>
|
style="border-radius: 30px; min-width: 250px; max-height: 350px;"></v-img>
|
||||||
</v-col>
|
</v-col>
|
||||||
</v-row>
|
</v-row>
|
||||||
</v-container>
|
</v-container>
|
||||||
@@ -408,10 +408,9 @@
|
|||||||
<script async setup>
|
<script async setup>
|
||||||
import DefaultLayout from '@/layouts/DefaultLayout.vue';
|
import DefaultLayout from '@/layouts/DefaultLayout.vue';
|
||||||
import FooterLayout from '@/layouts/FooterLayout.vue';
|
import FooterLayout from '@/layouts/FooterLayout.vue';
|
||||||
import { useClient } from '@/plugins/clientPlugin';
|
import {useClient} from "@/plugins/api.js";
|
||||||
import { ref } from 'vue';
|
import {ref} from "vue";
|
||||||
import { useRouter } from 'vue-router';
|
import {useRouter} from "vue-router";
|
||||||
|
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const client = useClient();
|
const client = useClient();
|
||||||
|
|||||||
@@ -7,9 +7,6 @@ export default {
|
|||||||
theme: {
|
theme: {
|
||||||
extend: {},
|
extend: {},
|
||||||
},
|
},
|
||||||
theme: {
|
|
||||||
extend: {},
|
|
||||||
},
|
|
||||||
plugins: [],
|
plugins: [],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user