File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -40,6 +40,13 @@ module.exports = function (moduleOptions) {
4040 options
4141 } )
4242
43+ // Utilities
44+ this . addTemplate ( {
45+ src : resolve ( __dirname , './templates/auth.utilities.js' ) ,
46+ fileName : 'auth/auth.utilities.js' ,
47+ options
48+ } )
49+
4350 // Class
4451 this . addTemplate ( {
4552 src : resolve ( __dirname , './templates/auth.class.js' ) ,
Original file line number Diff line number Diff line change 11import Cookies from 'js-cookie'
22import { parse as parseCookie } from 'cookie'
3+ import { routeOption } from './auth.utilities'
34import getProp from 'dotprop'
45import Vue from 'vue'
56
@@ -59,7 +60,10 @@ export default class Auth {
5960 this . _loggedInWatcher =
6061 this . _loggedInWatcher ||
6162 this . watchState ( 'loggedIn' , ( ) => {
62- $auth . redirect ( 'home' )
63+ if ( routeOption ( this . $route , 'auth' , false ) ) {
64+ return
65+ }
66+ this . redirect ( 'home' )
6367 } )
6468
6569 return this . _loggedInWatcher
Original file line number Diff line number Diff line change 11import Middleware from '../middleware'
2+ import { routeOption } from "./auth.utilities" ;
23
34Middleware . auth = function ( ctx ) {
45 // Disable middleware if options: { auth: false } is set on the route
@@ -20,17 +21,3 @@ Middleware.auth = function (ctx) {
2021 ctx . app . $auth . redirect ( 'login' )
2122 }
2223}
23-
24- // Utility to get route option
25- function routeOption ( route , key , value ) {
26- return route . matched . some ( m => {
27- // Browser
28- if ( process . browser ) {
29- return Object . values ( m . components ) . some ( component => component . options [ key ] === value )
30- }
31- // SSR
32- return Object . values ( m . components ) . some ( component =>
33- Object . values ( component . _Ctor ) . some ( ctor => ctor . options && ctor . options [ key ] === value )
34- )
35- } )
36- }
Original file line number Diff line number Diff line change 1+ // Utility to get route option
2+ export const routeOption = ( route , key , value ) => {
3+ return route . matched . some ( m => {
4+ // Browser
5+ if ( process . browser ) {
6+ return Object . values ( m . components ) . some ( component => component . options [ key ] === value )
7+ }
8+ // SSR
9+ return Object . values ( m . components ) . some ( component =>
10+ Object . values ( component . _Ctor ) . some ( ctor => ctor . options && ctor . options [ key ] === value )
11+ )
12+ } )
13+ }
You can’t perform that action at this time.
0 commit comments