From eef07babe8ea29f4ddcf87be2017c5c561d4066f Mon Sep 17 00:00:00 2001 From: Dominic Villemure Date: Wed, 20 Mar 2024 01:13:33 -0400 Subject: [PATCH 1/4] Added basic stripe form WIP --- package-lock.json | 9 ++++ package.json | 1 + src/views/StripePayment.vue | 73 +++++++++++++++++++++++++++++++++ src/views/main/CreatorFolio.vue | 7 +++- 4 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 src/views/StripePayment.vue diff --git a/package-lock.json b/package-lock.json index bf6ac4c..915a947 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "0.0.0", "dependencies": { "@mdi/font": "^7.4.47", + "@stripe/stripe-js": "^3.0.10", "axios": "^1.6.7", "pinia": "^2.1.7", "vue": "^3.4.15", @@ -841,6 +842,14 @@ "win32" ] }, + "node_modules/@stripe/stripe-js": { + "version": "3.0.10", + "resolved": "https://registry.npmjs.org/@stripe/stripe-js/-/stripe-js-3.0.10.tgz", + "integrity": "sha512-CFRNha+aPXR8GrqJss2TbK1j4aSGZXQY8gx0hvaYiSp+dU7EK/Zs5uwFTSAgV+t8H4+jcZ/iBGajAvoMYOwy+A==", + "engines": { + "node": ">=12.16" + } + }, "node_modules/@types/estree": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.5.tgz", diff --git a/package.json b/package.json index 295825f..1a647ed 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ }, "dependencies": { "@mdi/font": "^7.4.47", + "@stripe/stripe-js": "^3.0.10", "axios": "^1.6.7", "pinia": "^2.1.7", "vue": "^3.4.15", diff --git a/src/views/StripePayment.vue b/src/views/StripePayment.vue new file mode 100644 index 0000000..4dbdf93 --- /dev/null +++ b/src/views/StripePayment.vue @@ -0,0 +1,73 @@ + + + \ No newline at end of file diff --git a/src/views/main/CreatorFolio.vue b/src/views/main/CreatorFolio.vue index 6936fe2..1784e21 100644 --- a/src/views/main/CreatorFolio.vue +++ b/src/views/main/CreatorFolio.vue @@ -488,12 +488,15 @@ style="margin-bottom: 26%; height: 70%; margin-left: -10px; background-color: rgb(11, 170, 178); color: white; font-weight: bold;" class="mt-4" block>Envoyez - + + + + @@ -577,7 +580,7 @@ diff --git a/src/views/StripePayment.vue b/src/views/StripePayment.vue index 4dbdf93..a9a1584 100644 --- a/src/views/StripePayment.vue +++ b/src/views/StripePayment.vue @@ -1,35 +1,42 @@ + + From abab4587d163307577993b2a3c423dc5a2c1cdd7 Mon Sep 17 00:00:00 2001 From: Kamigen <46357922+Edouard127@users.noreply.github.com> Date: Sat, 30 Mar 2024 21:35:19 -0400 Subject: [PATCH 4/4] Refactor!: Codebase --- .env.development | 1 + .env.production | 1 + src/layouts/DefaultLayout.vue | 10 +++--- src/main.js | 2 +- src/plugins/api.js | 35 +++++++++++++++++++ src/plugins/clientPlugin.js | 34 ------------------ .../store/authStore.js => stores/auth.js} | 7 ++-- src/views/LoginView.vue | 16 +++++---- src/views/StripePayment.vue | 8 ++--- src/views/main/HomeView.vue | 13 ++++--- tailwind.config.js | 3 -- 11 files changed, 64 insertions(+), 66 deletions(-) create mode 100644 .env.development create mode 100644 .env.production create mode 100644 src/plugins/api.js delete mode 100644 src/plugins/clientPlugin.js rename src/{plugins/store/authStore.js => stores/auth.js} (97%) diff --git a/.env.development b/.env.development new file mode 100644 index 0000000..d823d9f --- /dev/null +++ b/.env.development @@ -0,0 +1 @@ +VITE_API_URL=http://localhost:5001/api/v1 diff --git a/.env.production b/.env.production new file mode 100644 index 0000000..5a800a5 --- /dev/null +++ b/.env.production @@ -0,0 +1 @@ +VITE_API_URL=todo diff --git a/src/layouts/DefaultLayout.vue b/src/layouts/DefaultLayout.vue index 59379ed..7690bad 100644 --- a/src/layouts/DefaultLayout.vue +++ b/src/layouts/DefaultLayout.vue @@ -118,18 +118,18 @@ - \ No newline at end of file + diff --git a/src/main.js b/src/main.js index e55acf4..39f62fb 100644 --- a/src/main.js +++ b/src/main.js @@ -8,7 +8,7 @@ import 'vuetify/styles' import { createVuetify } from 'vuetify' import * as components from 'vuetify/components' import * as directives from 'vuetify/directives' -import clientPlugin from './plugins/clientPlugin' +import clientPlugin from './plugins/api.js' const vuetify = createVuetify({ components, diff --git a/src/plugins/api.js b/src/plugins/api.js new file mode 100644 index 0000000..ee75e5b --- /dev/null +++ b/src/plugins/api.js @@ -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; +} + diff --git a/src/plugins/clientPlugin.js b/src/plugins/clientPlugin.js deleted file mode 100644 index c5faed0..0000000 --- a/src/plugins/clientPlugin.js +++ /dev/null @@ -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; -} \ No newline at end of file diff --git a/src/plugins/store/authStore.js b/src/stores/auth.js similarity index 97% rename from src/plugins/store/authStore.js rename to src/stores/auth.js index cf0fef0..bc2c12f 100644 --- a/src/plugins/store/authStore.js +++ b/src/stores/auth.js @@ -2,7 +2,7 @@ import { defineStore } from 'pinia'; const baseUrl = '/api/Users'; -export const useAuthStore = defineStore({ +export const auth = defineStore({ id: 'auth', state: () => ({ user: null, @@ -26,9 +26,6 @@ export const useAuthStore = defineStore({ } catch (error) { throw new Error('Login failed.') } - - - }, logout() { localStorage.setItem('jwt', ''); @@ -52,4 +49,4 @@ export const useAuthStore = defineStore({ clearTimeout(this.refreshTokenTimeout); } } -}); \ No newline at end of file +}); diff --git a/src/views/LoginView.vue b/src/views/LoginView.vue index 701d1bf..8218cd6 100644 --- a/src/views/LoginView.vue +++ b/src/views/LoginView.vue @@ -96,13 +96,15 @@ \ No newline at end of file + diff --git a/src/views/main/HomeView.vue b/src/views/main/HomeView.vue index d7e7f91..57b3ca5 100644 --- a/src/views/main/HomeView.vue +++ b/src/views/main/HomeView.vue @@ -15,7 +15,7 @@ Connexion @@ -193,14 +193,14 @@ + style="margin-bottom: 4%; border-radius: 30px; width: 80vw;"> + style="border-radius: 30px; min-width: 250px; max-height: 350px;"> @@ -408,10 +408,9 @@