From 6b7129f523c6186f137a2744c67161c33f11eb6e Mon Sep 17 00:00:00 2001 From: Dhaverd Date: Sun, 27 Oct 2024 03:08:51 +0800 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=B0=D0=BA=D0=BE=D0=BD=D0=B5=D1=86=20?= =?UTF-8?q?=D0=BF=D0=BE=D0=BD=D1=8F=D0=BB=20=D0=BA=D0=B0=D0=BA=20=D1=80?= =?UTF-8?q?=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5=D1=82=20=D0=B0=D1=83=D1=82?= =?UTF-8?q?=D0=B5=D0=BD=D1=82=D0=B8=D1=84=D0=B8=D0=BA=D0=B0=D1=86=D0=B8?= =?UTF-8?q?=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/AuthController.php | 2 + resources/app.js | 9 ++- resources/store/user.js | 15 ++-- resources/views/{ => Auth}/AuthButtons.vue | 2 +- resources/views/Auth/Login.vue | 13 ++-- resources/views/Auth/Registration.vue | 7 +- resources/views/Welcome.vue | 81 +++++++++++++++++++--- resources/views/Wishlist/Wishlist.vue | 13 ++++ 8 files changed, 120 insertions(+), 22 deletions(-) rename resources/views/{ => Auth}/AuthButtons.vue (97%) create mode 100644 resources/views/Wishlist/Wishlist.vue diff --git a/app/Http/Controllers/AuthController.php b/app/Http/Controllers/AuthController.php index 5ae163b..d4ae7ea 100644 --- a/app/Http/Controllers/AuthController.php +++ b/app/Http/Controllers/AuthController.php @@ -39,6 +39,7 @@ class AuthController extends Controller return response()->json([ 'message' => 'Successfully created user!', + 'user' => $user, 'accessToken'=> $token, ],201); } @@ -76,6 +77,7 @@ class AuthController extends Controller return response()->json([ 'accessToken' =>$token, + 'user' => $user, 'token_type' => 'Bearer', ]); } diff --git a/resources/app.js b/resources/app.js index da9b35c..6779ee6 100644 --- a/resources/app.js +++ b/resources/app.js @@ -7,22 +7,25 @@ import * as components from 'vuetify/components' import * as directives from 'vuetify/directives' import '@mdi/font/css/materialdesignicons.css' import { createMemoryHistory, createRouter } from 'vue-router' +import {createPinia} from "pinia"; const vuetify = createVuetify({ components, directives }) -import AuthButtons from './views/AuthButtons.vue' +import AuthButtons from './views/Auth/AuthButtons.vue' import Login from './views/Auth/Login.vue' import Registration from './views/Auth/Registration.vue' import Welcome from './views/Welcome.vue' +import Wishlist from "./views/Wishlist/Wishlist.vue"; const routes = [ { path: '/', component: Welcome }, { path: '/auth_options', component: AuthButtons }, { path: '/login', component: Login }, { path: '/registration', component: Registration }, + { path: '/wishlist', component: Wishlist }, ] const router = createRouter({ @@ -30,4 +33,6 @@ const router = createRouter({ routes, }) -createApp(App).use(vuetify).use(router).mount("#app") +const pinia = createPinia() + +createApp(App).use(vuetify).use(router).use(pinia).mount("#app") diff --git a/resources/store/user.js b/resources/store/user.js index 1958de4..db2d8b8 100644 --- a/resources/store/user.js +++ b/resources/store/user.js @@ -1,14 +1,19 @@ import { defineStore } from 'pinia' export const useUserStore = defineStore('user', { - state: () => { - return { user: null } - }, + state: () => ({ + user: null, + token: localStorage.getItem('auth_token') || null, + }), // could also be defined as // state: () => ({ count: 0 }) actions: { - increment() { - this.count++ + setUser(user) { + this.user = user; + }, + setToken(token) { + this.token = token; + localStorage.setItem('auth_token', token); }, }, }) diff --git a/resources/views/AuthButtons.vue b/resources/views/Auth/AuthButtons.vue similarity index 97% rename from resources/views/AuthButtons.vue rename to resources/views/Auth/AuthButtons.vue index a0d6fa6..8d133ac 100644 --- a/resources/views/AuthButtons.vue +++ b/resources/views/Auth/AuthButtons.vue @@ -5,7 +5,7 @@ export default {