├── .env.example ├── .eslintrc.js ├── .prettierrc.json ├── LICENSE.md ├── README.md ├── index.html ├── jsconfig.json ├── package.json ├── postcss.config.js ├── public └── favicon.ico ├── src ├── App.vue ├── components │ ├── ApplicationLogo.vue │ ├── Checkbox.vue │ ├── Dropdown.vue │ ├── DropdownLink.vue │ ├── InputError.vue │ ├── InputLabel.vue │ ├── NavLink.vue │ ├── PrimaryButton.vue │ ├── ResponsiveNavLink.vue │ ├── TextInput.vue │ └── ValidationErrors.vue ├── index.css ├── layouts │ ├── AuthenticatedLayout.vue │ └── GuestLayout.vue ├── lib │ └── axios.js ├── main.js ├── pages │ ├── Dashboard.vue │ ├── Welcome.vue │ ├── auth │ │ ├── ForgotPassword.vue │ │ ├── Login.vue │ │ ├── Register.vue │ │ ├── ResetPassword.vue │ │ └── VerifyEmail.vue │ └── errors │ │ └── 404.vue ├── router │ └── index.js └── stores │ └── user.js ├── tailwind.config.js └── vite.config.js /.env.example: -------------------------------------------------------------------------------- 1 | VITE_APP_NAME=Breeze Vue.js 3 Api 2 | VITE_PUBLIC_BACKEND_URL=http://localhost:8000 -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | env: { 3 | browser: true, 4 | es2021: true, 5 | 'vue/setup-compiler-macros': true, 6 | }, 7 | extends: [ 8 | // 'eslint:recommended', 9 | 'plugin:vue/vue3-recommended', 10 | 'prettier', 11 | ], 12 | parser: 'vue-eslint-parser', 13 | parserOptions: { 14 | ecmaVersion: 'latest', 15 | sourceType: 'module', 16 | }, 17 | plugins: ['vue'], 18 | rules: { 19 | 'vue/require-prop-types': 0, 20 | 'vue/multi-word-component-names': 'off', 21 | }, 22 | } 23 | -------------------------------------------------------------------------------- /.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "arrowParens": "avoid", 3 | "bracketSameLine": true, 4 | "semi": false, 5 | "singleQuote": true, 6 | "tabWidth": 4, 7 | "trailingComma": "all" 8 | } 9 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Faisal Fajri 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Laravel Breeze - Vue.js 3 Edition 2 | 3 | ## Inspiration 4 | 5 | This project was inspired by the [Breeze Next.js](https://github.com/laravel/breeze-next) project. 🏝️ 6 | 7 | ## Introduction 8 | 9 | This repository is an implementing of the [Laravel Breeze](https://laravel.com/docs/starter-kits) application / authentication starter kit frontend in [Vue.js](https://vuejs.org). All of the authentication boilerplate is already written for you - powered by [Laravel Sanctum](https://laravel.com/docs/sanctum), allowing you to quickly begin pairing your beautiful Vue.js frontend with a powerful Laravel backend. 10 | 11 | ## Documentation 12 | 13 | ### Installation 14 | 15 | First, create a Vue.js compatible Laravel backend by installing Laravel Breeze into a [fresh Laravel application](https://laravel.com/docs/installation) and installing Breeze's API scaffolding: 16 | 17 | ```bash 18 | # Create the Laravel application... 19 | laravel new vue-backend 20 | 21 | cd vue-backend 22 | 23 | # Install Breeze and dependencies... 24 | composer require laravel/breeze 25 | 26 | php artisan breeze:install api 27 | ``` 28 | 29 | Next, ensure that your application's `APP_URL` and `FRONTEND_URL` environment variables are set to `http://localhost:8000` and `http://localhost:3000`, respectively. 30 | 31 | After defining the appropriate environment variables, you may serve the Laravel application using the `serve` Artisan command: 32 | 33 | ```bash 34 | # Serve the application... 35 | php artisan serve 36 | ``` 37 | 38 | Next, clone this repository and install its dependencies with `yarn install` or `npm install`. Then, copy the `.env.example` file to `.env` and supply the URL of your backend: 39 | 40 | ``` 41 | VITE_APP_NAME=Breeze Vue.js 3 Api 42 | VITE_PUBLIC_BACKEND_URL=http://localhost:8000 43 | ``` 44 | 45 | Finally, run the application via `npm run dev`. The application will be available at `http://localhost:3000`: 46 | 47 | ``` 48 | npm run dev 49 | ``` 50 | 51 | > Note: Currently, we recommend using `localhost` during local development of your backend and frontend to avoid CORS "Same-Origin" issues. 52 | 53 | ## License 54 | 55 | Laravel Breeze - Vue.js 3 Edition is open-sourced software licensed under the [MIT license](LICENSE.md). -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Breeze Vue.js 3 Api 10 | 11 | 12 |
13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /jsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "include": ["./src/**/*"] 3 | } 4 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "breeze-vue-api", 3 | "private": true, 4 | "version": "0.1.0", 5 | "scripts": { 6 | "dev": "vite", 7 | "build": "vite build", 8 | "preview": "vite preview", 9 | "lint": "eslint --ext .js,.vue ./src", 10 | "lint:fix": "eslint --fix --ext .js,.vue ./src", 11 | "tier:check": "prettier --check 'src/**/*'", 12 | "tier:write": "prettier --write 'src/**/*'" 13 | }, 14 | "dependencies": { 15 | "@vueuse/core": "^9.13.0", 16 | "axios": "^1.3.4", 17 | "pinia": "^2.0.33", 18 | "vue": "^3.2.47", 19 | "vue-router": "^4.1.6" 20 | }, 21 | "devDependencies": { 22 | "@tailwindcss/forms": "^0.5.3", 23 | "@vitejs/plugin-vue": "^4.1.0", 24 | "autoprefixer": "^10.4.14", 25 | "eslint": "^8.36.0", 26 | "eslint-config-prettier": "^8.8.0", 27 | "eslint-plugin-vue": "^9.10.0", 28 | "postcss": "^8.4.21", 29 | "prettier": "^2.8.6", 30 | "tailwindcss": "^3.2.7", 31 | "vite": "^4.2.1" 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /postcss.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: { 3 | tailwindcss: {}, 4 | autoprefixer: {}, 5 | }, 6 | } 7 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faisalfjri/breeze-vue-api/6fe4019137e90cd67322cb79c284d54f7b4f6d50/public/favicon.ico -------------------------------------------------------------------------------- /src/App.vue: -------------------------------------------------------------------------------- 1 | 4 | -------------------------------------------------------------------------------- /src/components/ApplicationLogo.vue: -------------------------------------------------------------------------------- 1 | 7 | -------------------------------------------------------------------------------- /src/components/Checkbox.vue: -------------------------------------------------------------------------------- 1 | 26 | 27 | 34 | -------------------------------------------------------------------------------- /src/components/Dropdown.vue: -------------------------------------------------------------------------------- 1 | 43 | 44 | 78 | -------------------------------------------------------------------------------- /src/components/DropdownLink.vue: -------------------------------------------------------------------------------- 1 | 8 | -------------------------------------------------------------------------------- /src/components/InputError.vue: -------------------------------------------------------------------------------- 1 | 4 | 5 | 12 | -------------------------------------------------------------------------------- /src/components/InputLabel.vue: -------------------------------------------------------------------------------- 1 | 4 | 5 | 11 | -------------------------------------------------------------------------------- /src/components/NavLink.vue: -------------------------------------------------------------------------------- 1 | 12 | 13 | 18 | -------------------------------------------------------------------------------- /src/components/PrimaryButton.vue: -------------------------------------------------------------------------------- 1 | 12 | 13 | 40 | -------------------------------------------------------------------------------- /src/components/ResponsiveNavLink.vue: -------------------------------------------------------------------------------- 1 | 13 | 14 | 19 | -------------------------------------------------------------------------------- /src/components/TextInput.vue: -------------------------------------------------------------------------------- 1 | 16 | 17 | 24 | -------------------------------------------------------------------------------- /src/components/ValidationErrors.vue: -------------------------------------------------------------------------------- 1 | 4 | 5 | 15 | -------------------------------------------------------------------------------- /src/index.css: -------------------------------------------------------------------------------- 1 | @tailwind base; 2 | @tailwind components; 3 | @tailwind utilities; 4 | -------------------------------------------------------------------------------- /src/layouts/AuthenticatedLayout.vue: -------------------------------------------------------------------------------- 1 | 26 | 27 | 194 | -------------------------------------------------------------------------------- /src/layouts/GuestLayout.vue: -------------------------------------------------------------------------------- 1 | 4 | 5 | 20 | -------------------------------------------------------------------------------- /src/lib/axios.js: -------------------------------------------------------------------------------- 1 | import Axios from 'axios' 2 | 3 | const axios = Axios.create({ 4 | baseURL: import.meta.env.VITE_PUBLIC_BACKEND_URL, 5 | headers: { 6 | 'X-Requested-With': 'XMLHttpRequest', 7 | }, 8 | withCredentials: true, 9 | withXSRFToken: true 10 | }) 11 | 12 | export default axios 13 | -------------------------------------------------------------------------------- /src/main.js: -------------------------------------------------------------------------------- 1 | import { createApp, markRaw } from 'vue' 2 | import { createPinia } from 'pinia' 3 | import App from './App.vue' 4 | import router from './router' 5 | import './index.css' 6 | 7 | const app = createApp(App) 8 | const pinia = createPinia() 9 | 10 | app.use( 11 | pinia.use(({ store }) => { 12 | store.router = markRaw(router) 13 | }), 14 | ) 15 | app.use(router) 16 | app.mount('#app') 17 | -------------------------------------------------------------------------------- /src/pages/Dashboard.vue: -------------------------------------------------------------------------------- 1 | 4 | 5 | 24 | -------------------------------------------------------------------------------- /src/pages/Welcome.vue: -------------------------------------------------------------------------------- 1 | 8 | 9 | 299 | 300 | 363 | -------------------------------------------------------------------------------- /src/pages/auth/ForgotPassword.vue: -------------------------------------------------------------------------------- 1 | 30 | 31 | 66 | -------------------------------------------------------------------------------- /src/pages/auth/Login.vue: -------------------------------------------------------------------------------- 1 | 34 | 35 | 90 | -------------------------------------------------------------------------------- /src/pages/auth/Register.vue: -------------------------------------------------------------------------------- 1 | 30 | 31 | 97 | -------------------------------------------------------------------------------- /src/pages/auth/ResetPassword.vue: -------------------------------------------------------------------------------- 1 | 36 | 37 | 86 | -------------------------------------------------------------------------------- /src/pages/auth/VerifyEmail.vue: -------------------------------------------------------------------------------- 1 | 32 | 33 | 63 | -------------------------------------------------------------------------------- /src/pages/errors/404.vue: -------------------------------------------------------------------------------- 1 | 9 | 10 | 77 | -------------------------------------------------------------------------------- /src/router/index.js: -------------------------------------------------------------------------------- 1 | import { createWebHistory, createRouter } from 'vue-router' 2 | import { useUsers } from '@/stores/user' 3 | import Welcome from '@/pages/Welcome.vue' 4 | import PageNotFound from '@/pages/errors/404.vue' 5 | import Dashboard from '@/pages/Dashboard.vue' 6 | import Login from '@/pages/auth/Login.vue' 7 | import Register from '@/pages/auth/Register.vue' 8 | import ForgotPassword from '@/pages/auth/ForgotPassword.vue' 9 | import ResetPassword from '@/pages/auth/ResetPassword.vue' 10 | import VerifyEmail from '@/pages/auth/VerifyEmail.vue' 11 | 12 | const APP_NAME = import.meta.env.VITE_APP_NAME 13 | 14 | const routes = [ 15 | { 16 | path: '/', 17 | name: 'welcome', 18 | component: Welcome, 19 | meta: { 20 | title: 'Welcome', 21 | metaTags: [ 22 | { 23 | name: 'Welcome', 24 | content: 25 | 'An application / authentication starter kit frontend in Vue.js 3 for Laravel Breeze.', 26 | }, 27 | { 28 | property: 'og:Welcome', 29 | content: 30 | 'An application / authentication starter kit frontend in Vue.js 3 for Laravel Breeze.', 31 | }, 32 | ], 33 | }, 34 | }, 35 | { 36 | path: '/home', 37 | redirect: '/dashboard', 38 | component: Dashboard, 39 | query: { 40 | verified: 'verified', 41 | }, 42 | meta: { 43 | guard: 'auth', 44 | }, 45 | }, 46 | { 47 | path: '/dashboard', 48 | name: 'dashboard', 49 | component: Dashboard, 50 | meta: { 51 | title: 'Dashboard', 52 | guard: 'auth', 53 | }, 54 | }, 55 | { 56 | path: '/login', 57 | name: 'login', 58 | component: Login, 59 | query: { 60 | reset: 'reset', 61 | }, 62 | meta: { 63 | title: 'Log in', 64 | guard: 'guest', 65 | }, 66 | }, 67 | { 68 | path: '/register', 69 | name: 'register', 70 | component: Register, 71 | meta: { 72 | title: 'Register', 73 | guard: 'guest', 74 | }, 75 | }, 76 | { 77 | path: '/forgot-password', 78 | name: 'forgot-password', 79 | component: ForgotPassword, 80 | meta: { 81 | title: 'Forget Password', 82 | guard: 'guest', 83 | }, 84 | }, 85 | { 86 | path: '/password-reset/:token', 87 | name: 'password-reset', 88 | component: ResetPassword, 89 | query: { 90 | email: 'email', 91 | }, 92 | meta: { 93 | title: 'Reset Password', 94 | guard: 'guest', 95 | }, 96 | }, 97 | { 98 | path: '/verify-email', 99 | name: 'verify-email', 100 | component: VerifyEmail, 101 | query: { 102 | resend: 'resend', 103 | }, 104 | meta: { 105 | title: 'Email Verification', 106 | guard: 'auth', 107 | }, 108 | }, 109 | { 110 | path: '/page-not-found', 111 | name: 'page-not-found', 112 | component: PageNotFound, 113 | meta: { 114 | title: 'Page Not Found', 115 | }, 116 | }, 117 | { 118 | path: '/:pathMatch(.*)*', 119 | redirect: '/page-not-found', 120 | }, 121 | ] 122 | 123 | const router = createRouter({ 124 | history: createWebHistory(), 125 | routes, 126 | }) 127 | 128 | // Navigation guard 129 | 130 | router.beforeEach((to, from, next) => { 131 | const store = useUsers() 132 | 133 | const auth = store.authUser 134 | 135 | if (to.matched.some(route => route.meta.guard === 'guest') && auth) 136 | next({ name: 'dashboard' }) 137 | else if (to.matched.some(route => route.meta.guard === 'auth') && !auth) 138 | next({ name: 'login' }) 139 | else next() 140 | }) 141 | 142 | // Page Title and Metadata 143 | 144 | router.beforeEach((to, from, next) => { 145 | const nearestWithTitle = to.matched 146 | .slice() 147 | .reverse() 148 | .find(r => r.meta && r.meta.title) 149 | 150 | const nearestWithMeta = to.matched 151 | .slice() 152 | .reverse() 153 | .find(r => r.meta && r.meta.metaTags) 154 | 155 | if (nearestWithTitle) { 156 | document.title = nearestWithTitle.meta.title + ' - ' + APP_NAME 157 | } else { 158 | document.title = APP_NAME 159 | } 160 | 161 | Array.from(document.querySelectorAll('[data-vue-router-controlled]')).map( 162 | el => el.parentNode.removeChild(el), 163 | ) 164 | 165 | if (!nearestWithMeta) return next() 166 | 167 | nearestWithMeta.meta.metaTags 168 | .map(tagDef => { 169 | const tag = document.createElement('meta') 170 | 171 | Object.keys(tagDef).forEach(key => { 172 | tag.setAttribute(key, tagDef[key]) 173 | }) 174 | 175 | tag.setAttribute('data-vue-router-controlled', '') 176 | 177 | return tag 178 | }) 179 | 180 | .forEach(tag => document.head.appendChild(tag)) 181 | 182 | next() 183 | }) 184 | 185 | export default router 186 | -------------------------------------------------------------------------------- /src/stores/user.js: -------------------------------------------------------------------------------- 1 | import axios from '@/lib/axios' 2 | import { useStorage } from '@vueuse/core' 3 | import { defineStore, acceptHMRUpdate } from 'pinia' 4 | 5 | const csrf = () => axios.get('/sanctum/csrf-cookie') 6 | 7 | export const useUsers = defineStore('users', { 8 | state: () => ({ 9 | userData: useStorage('userData', []), 10 | authStatus: useStorage('authStatus', []), 11 | }), 12 | 13 | getters: { 14 | authUser: state => state.authStatus === 204, 15 | hasUserData: state => Object.keys(state.userData).length > 0, 16 | hasVerified: state => 17 | Object.keys(state.userData).length > 0 18 | ? state.userData.email_verified_at !== null 19 | : false, 20 | }, 21 | 22 | actions: { 23 | getData() { 24 | axios 25 | .get('/api/user') 26 | .then(response => { 27 | this.userData = response.data 28 | }) 29 | .catch(error => { 30 | if (error.response.status !== 409) throw error 31 | 32 | this.router.push('/verify-email') 33 | }) 34 | }, 35 | 36 | async register(form, setErrors, processing) { 37 | await csrf() 38 | 39 | processing.value = true 40 | 41 | axios 42 | .post('/register', form.value) 43 | .then(response => { 44 | this.authStatus = response.status 45 | processing.value = false 46 | 47 | this.router.push({ name: 'dashboard' }) 48 | }) 49 | .catch(error => { 50 | if (error.response.status !== 422) throw error 51 | 52 | setErrors.value = Object.values( 53 | error.response.data.errors, 54 | ).flat() 55 | processing.value = false 56 | }) 57 | }, 58 | 59 | async login(form, setErrors, processing) { 60 | await csrf() 61 | 62 | processing.value = true 63 | 64 | axios 65 | .post('/login', form.value) 66 | .then(response => { 67 | this.authStatus = response.status 68 | processing.value = false 69 | 70 | this.router.push({ name: 'dashboard' }) 71 | }) 72 | .catch(error => { 73 | if (error.response.status !== 422) throw error 74 | 75 | setErrors.value = Object.values( 76 | error.response.data.errors, 77 | ).flat() 78 | processing.value = false 79 | }) 80 | }, 81 | 82 | async forgotPassword(form, setStatus, setErrors, processing) { 83 | await csrf() 84 | 85 | processing.value = true 86 | 87 | axios 88 | .post('/forgot-password', form.value) 89 | .then(response => { 90 | setStatus.value = response.data.status 91 | processing.value = false 92 | }) 93 | .catch(error => { 94 | if (error.response.status !== 422) throw error 95 | 96 | setErrors.value = Object.values( 97 | error.response.data.errors, 98 | ).flat() 99 | processing.value = false 100 | }) 101 | }, 102 | 103 | async resetPassword(form, setErrors, processing) { 104 | await csrf() 105 | 106 | processing.value = true 107 | 108 | axios 109 | .post('/reset-password', form.value) 110 | .then(response => { 111 | this.router.push( 112 | '/login?reset=' + btoa(response.data.status), 113 | ) 114 | processing.value = false 115 | }) 116 | .catch(error => { 117 | if (error.response.status !== 422) throw error 118 | 119 | setErrors.value = Object.values( 120 | error.response.data.errors, 121 | ).flat() 122 | processing.value = false 123 | }) 124 | }, 125 | 126 | resendEmailVerification(setStatus, processing) { 127 | processing.value = true 128 | 129 | axios.post('/email/verification-notification').then(response => { 130 | setStatus.value = response.data.status 131 | processing.value = false 132 | }) 133 | }, 134 | 135 | async logout() { 136 | await axios 137 | .post('/logout') 138 | .then(() => { 139 | this.$reset() 140 | this.userData = {} 141 | this.authStatus = [] 142 | 143 | this.router.push({ name: 'welcome' }) 144 | }) 145 | .catch(error => { 146 | if (error.response.status !== 422) throw error 147 | }) 148 | }, 149 | }, 150 | }) 151 | 152 | if (import.meta.hot) { 153 | import.meta.hot.accept(acceptHMRUpdate(useUsers, import.meta.hot)) 154 | } 155 | -------------------------------------------------------------------------------- /tailwind.config.js: -------------------------------------------------------------------------------- 1 | const defaultTheme = require('tailwindcss/defaultTheme') 2 | 3 | module.exports = { 4 | content: ['./index.html', './src/**/*.{vue,js,ts,jsx,tsx}'], 5 | theme: { 6 | extend: { 7 | fontFamily: { 8 | sans: ['Nunito', ...defaultTheme.fontFamily.sans], 9 | }, 10 | }, 11 | }, 12 | plugins: [require('@tailwindcss/forms')], 13 | } 14 | -------------------------------------------------------------------------------- /vite.config.js: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vite' 2 | import vue from '@vitejs/plugin-vue' 3 | const path = require('path') 4 | 5 | // https://vitejs.dev/config/ 6 | export default defineConfig({ 7 | server: { 8 | port: 3000, 9 | }, 10 | resolve: { 11 | alias: { 12 | '@': path.resolve(__dirname, './src'), 13 | }, 14 | }, 15 | plugins: [vue()], 16 | }) 17 | --------------------------------------------------------------------------------