Giter Site home page Giter Site logo

lbwa / vue-auth-boilerplate Goto Github PK

View Code? Open in Web Editor NEW
35.0 2.0 8.0 3.59 MB

๐Ÿ”‘ Vue.js scalable boilerplate with user authentication.

JavaScript 13.92% Vue 34.47% HTML 3.56% TypeScript 47.52% Shell 0.05% Sass 0.47%
vuejs dashboard admin-template administrator-dashboard access-control vue-admin administration-dashboard vue vue-router webpack vue-cli v-access private-routes material-design authentication route-protection dynamic-routes boilerplate console-boilerplate vue-boilerplate

vue-auth-boilerplate's Introduction

Vue auth boilerplate

github actions - tests github actions - deployment nodejs version

Vue.js console boilerplate with authentication.

Prerequisites

Please make sure you have installed node.js version 8.9 or above (the LTS version recommended).

Development

  • install all dependencies

    $ npm i
  • start development server

    $ npm run serve

    Frontend server is running at http://localhost:8080 and http://<YOUR_DEVICE_LOCAL_IP>:8080 with hot module replacement.

  • run unit tests

    $ npm run test:unit

Production build

$ npm run build
# yarn build

CDN supporting

This project production build has supported third-party CDN libraries out of the box. All JS/CSS library CDN urls should be recorded by third-parties.js. syntax like:

interface CDNUrl {
  name: string // required for js, npm package name
  library: string // required for js, global variable name in the browser
  js: string // js cdn file urls
  css: string // css cdn file urls
}
  • JS libraries

    const thirdParties = [
      // ... other js/css libraries
    +  {
    +    name: 'vue',
    +    library: 'Vue',
    +    js: 'https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.min.js'
    +  }
    ]
  • Pure CSS libraries

    step 1. You should import pure css libraries with tree-shaking.

    - import 'normalize.css'
    + if (__DEV__) { // __DEV__ is an environment variable
    +    require('normalize.css')
    + }

    step 2. add css library CDN link into third-parties.js.

    const thirdParties = [
      // ... other js/css libraries
    +  {
    +    css: 'https://cdn.jsdelivr.net/npm/[email protected]/normalize.min.css'
    +  }
    ]

User authentication

Please refer to v-access documentation.

Symbolic constants

A symbolic constant is a name given to a constant literal value. It's usually used to prevent magic numbers and hard-coding. All symbolic constants should be recorded in the src/constants.ts file.

  • Q: When should I use symbolic constants?

  • A: Feature flag, public settings, etc.

Environment variables

All node.js use-defined environment should be record at the <PROJECT_ROOT>/.env* files and start with VUE_APP_* prefix character. You can find more details from the @vue/cli documentation.

Declarations

All global TypeScript declarations should be recorded in the src/global.d.ts file.

This boilerplate has supported multiple declarations for CSS pre-process languages in src/global.d.ts.

Layouts

In practice, we perhaps have two different kinds of layout components. All layout components should be placed in the src/layouts directory.

type description character
route-based layout with <router-view/> src/layouts/R*.vue
non-route-based layout without <router-view/> src/layouts/L*.vue

Use route-based layout

A valid router config should be based on the following structure:

interface ConsoleRouteConfig extends RouteConfig {
  meta?: Partial<{
    layout: string // which route-based layout need to be rendered
    hidden: boolean
    icon: string
    title: string
  }>
}

We use meta.layout to decide which layout component we need to be rendered.

Use non-route-based layout

As opposed to route-based layout, you should always import non-route-based layout component manually.

import { NonRouteBasedLayout } from '@/layouts/NonRouteBasedLayout'

export default {
  name: 'AnyViewComponent',

  components: {
    NonRouteBasedLayout
  }
}

Components

We also have multiple kinds of components and should be placed in src/components directory.

component type description example character
presentational represent user interface view excluding any state basic component Base*.vue
container state including all business logic any sub views/layouts component [VIEW_PREFIX]*.vue

Plugins

If any Vue.js plugin exists, it should be placed in src/plugins directory.

Effects

All HTTP request function should be placed in src/effects directory, and should be occurred by Initiator instance which has encapsulated axios creation and registered two interceptors automatically by default.

import { createInitiator } from './initiator'

const { http } = createInitiator(/* support all AxiosRequestConfig */)

export function fetchUserProfile(username: string, password: string) {
  return http.post('/user/profile', {
    username,
    password
  })
}

Based on single responsibility principle and better universality, every request route should be a singleton. All request or response errors should be handle by Http request consumer, instead of itself.

Router

filename description
guards.ts store all navigation guards
index.ts export a vue-router instance
routes.ts record all valid preset static routes

Route config

We add serval meta properties for global navigation sidebar.

interface ConsoleRouteConfig extends RouteConfig {
  meta?: Partial<{
    layout: string // which route-based layout need to be rendered
    hidden: boolean
    icon: string
    title: string
  }>
}
property name description
meta.layout Which route-based layout should be rendered
meta.hidden Whether route should be rendered by global navigation sidebar
meta.icon Route material design icon icon in the global navigation sidebar
meta.title Route title in the global navigation sidebar

Note that Route only be rendered when meta.title and meta.hidden is truthy value.

State management

We use Vuex to implement global state management.

Automatic registration

All store module placed in src/store/modules/*.ts would be registered automatically. Every module would use their filename as store module namespace.

With request effects

Actions can contain arbitrary asynchronous operations.

All HTTP requests should be called by an action if an HTTP request result needs to be stored in the vuex store, instead of calling HTTP request directly.

dispatch an action --> http effects --> commit mutation in an action --> store the result of effects

Handle error

store.dispatch always return a Promise instance.

Any action internal error should be handled by action consumer, instead of action itself.

action's error --> throw --as rejected promise--> handled by any action consumer

History store module

We have a history (store/modules/history.ts) store module that used to record any visited vue-route record with meta.title field.

Changelog

All notable changes to this repository will be documented in CHANGELOG file.

License

MIT ยฉ Bowen Liu

vue-auth-boilerplate's People

Contributors

dependabot[bot] avatar lbwa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

vue-auth-boilerplate's Issues

`npm run serve` fails with latest release

A peculiar problem, if I download v3.0.0 from npm run serve fails,

DJF2:vue-auth-boilerplate-3.0.0 daniel$ npm run serve
> [email protected] serve /Users/daniel/Downloads/vue-auth-boilerplate-3.0.0
> vue-cli-service serve

 INFO  Starting development server...
fatal: not a git repository (or any of the parent directories): .git
 ERROR  Error: Command failed: git rev-parse HEAD
fatal: not a git repository (or any of the parent directories): .git

Error: Command failed: git rev-parse HEAD
fatal: not a git repository (or any of the parent directories): .git

    at checkExecSyncError (child_process.js:611:11)
    at Object.execSync (child_process.js:647:15)
    at /Users/daniel/Downloads/vue-auth-boilerplate-3.0.0/vue.config.js:22:12
    at Object.tap (/Users/daniel/Downloads/vue-auth-boilerplate-3.0.0/node_modules/webpack-chain/src/Plugin.js:25:24)
    at chainWebpack (/Users/daniel/Downloads/vue-auth-boilerplate-3.0.0/vue.config.js:16:29)
    at /Users/daniel/Downloads/vue-auth-boilerplate-3.0.0/node_modules/@vue/cli-service/lib/Service.js:236:40
    at Array.forEach (<anonymous>)
    at Service.resolveChainableWebpackConfig (/Users/daniel/Downloads/vue-auth-boilerplate-3.0.0/node_modules/@vue/cli-service/lib/Service.js:236:26)
    at Service.resolveWebpackConfig (/Users/daniel/Downloads/vue-auth-boilerplate-3.0.0/node_modules/@vue/cli-service/lib/Service.js:240:48)
    at PluginAPI.resolveWebpackConfig (/Users/daniel/Downloads/vue-auth-boilerplate-3.0.0/node_modules/@vue/cli-service/lib/PluginAPI.js:132:25)
    at serve (/Users/daniel/Downloads/vue-auth-boilerplate-3.0.0/node_modules/@vue/cli-service/lib/commands/serve.js:74:31)
    at Service.run (/Users/daniel/Downloads/vue-auth-boilerplate-3.0.0/node_modules/@vue/cli-service/lib/Service.js:230:12)
    at Object.<anonymous> (/Users/daniel/Downloads/vue-auth-boilerplate-3.0.0/node_modules/@vue/cli-service/bin/vue-cli-service.js:36:9)
    at Module._compile (internal/modules/cjs/loader.js:1176:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1196:10)
    at Module.load (internal/modules/cjs/loader.js:1040:32)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] serve: `vue-cli-service serve`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] serve script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/daniel/.npm/_logs/2020-05-03T21_08_34_134Z-debug.log

Is there some dependence on git? Because if do the same using git it works!

> git clone [email protected]:lbwa/vue-auth-boilerplate.git
> npm i
> npm run serve

Nested routes (components) are cached by parent routes (components)

Describe the bug
First-level components are cached by <keep-alive> from first-level <router-view>, including nested components matched nested routes.

To Reproduce
Steps to reproduce the behavior:

  1. Go to /form/step/confirm or /form/step/success
  2. Click on other routes (eg. routes from /form/step/confirm to /dashboard/analysis)
  3. Click button Step form in the aside menu
  4. See error: routes is default matched /form/step/info, but now nested routed is Step.1 matched component.

Expected behavior
Should matched correct nested components.

Desktop (please complete the following information):

  • OS: Windows 10
  • Browser chrome
  • Version 69.0.3497.100

Additional context
<keep-alive> cause this bug (fix) . <keep-alive> cached all first-level matched components, including all nested components matched nested routes.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.