Home Posts GitHub Menu

Vue Auth Options Examples



There are two sections outlined here.

The first is the core set of options while the second is the sub set of request options.

Core Options

rolesKey

@default 'roles'

The default field to check against on the user object when using "auth meta" or $auth.check().

Resources:

rememberKey

@default 'auth_remember'

The name under which the remember String is stored under.

Resources:

staySignedInKey

@default 'auth_stay_signed_in'

The name under which the staySignedIn option from login is stored.

Resources:

tokenDefaultKey

@default 'auth_token_default'

The name under which the default token String is stored under.

Resources:

tokenImpersonateKey

@default 'auth_token_impersonate'

The name under which the impersonate token String is stored under.

Resources:

stores

@default ['storage', 'cookie']

The order in which to attempt storage of "tokens" and "remember" String data.

Resources:

cookie

@default {
    Path: '/',
    Domain: null,
    Secure: true,
    Expires: 12096e5,
    SameSite: 'None'
}

The default params that will be set on cookies when cookie storage is enabled.

Resources:

authRedirect

@default {path: '/login'}

The router redirect to use if any authentication is required on a route.

This will trigger if meta.auth is set to anything other than undefined or false.

NOTE: This also accepts a callback function which passes the transition for dynamic handling.

Resources:

forbiddenRedirect

@default {path: '/403'}

The router redirect to use if a route is forbidden.

This will trigger if the user object's role property does not match up with the auth value.

NOTE: This also accepts a callback function which passes the transition for dynamic handling.

Resources:

notFoundRedirect

@default {path: '/404'}

The router redirect to use if route is "not found".

Typically used to hide pages while logged in. For instance we don't want the user to access a login or register page while they are authenticated. Hence a "404 Not Found".

This will trigger if auth.meta is set to false and the user is already authenticated.

NOTE: This also accepts a callback function which passes the transition for dynamic handling.

Resources:

registerData

@default {
    url: 'auth/register',
    method: 'POST',
    redirect: '/login',
    autoLogin: false
}

Default register request data.

NOTE: If the autoLogin is enabled it will subsequently trigger a login call. All options available to the login method will also be available here.

Resources:

loginData

@default {
    url: 'auth/login',
    method: 'POST',
    redirect: '/',
    fetchUser: true,
    staySignedIn: true
}

Default login request data.

Resources:

logoutData

@default {
    url: 'auth/logout',
    method: 'POST',
    redirect: '/',
    makeRequest: false
}

Default logout request data.

Resources:

oauth2Data

@default {
    url: 'auth/social',
    method: 'POST',
    redirect: '/',
    fetchUser: true
}

Default oauth2 request data.

NOTE: After token is received and the API request is made this will execute via the login method. All options available to the login method will also be available here.

Resources:

fetchData

@default {
    url: 'auth/user',
    method: 'GET',
    enabled: true
}

Default fetch request data.

Resources:

refreshData

@default {
    url: 'auth/refresh',
    method: 'GET',
    enabled: true,
    interval: 30
}

Default refresh request data.

Resources:

impersonateData

@default {
    url: 'auth/impersonate',
    method: 'POST',
    redirect: '/',
    fetchUser: true
}

Default impersonate request data.

Resources:

unimpersonateData

@default {
    url: 'auth/unimpersonate',
    method: 'POST',
    redirect: '/admin',
    fetchUser: true,
    makeRequest: false
}

Default unimpersonate request data.

Resources:

getUrl

@default _getUrl

The default url function used for redirect uri for bringing a user back to the app during oauth2 request.

Resources:

getDomain

@default _getDomain

The default domain function used when storing remember and token data in cookies.

Resources:

parseUserData

@default _parseUserData

The default parser for user response data.

Resources:

Request Options

redirect

@return Object|String

Specify the default router route redirect to use.

fetchUser

@return Boolean

Specify whether to fetch a user or not after a request.

For instance after login or oauth2 requests.

staySignedIn

@return Boolean

Specify whether the token data stored will be long lived or not.

Meaning does it expire after the browser is closed or not.

autoLogin

@return Boolean

Specify when the user should be auto logged in.

Used in register method.

remember

@return String

Specify a bit of string data to remember during login or register.

This is a dynamic opiton that should be set during the method call.

makeRequest

@return Boolean

Specify whether to trigger an API call first.

In some cases such as with logout or unimpersonate a request to the API may not be required.

enabled

@return Boolean

Specify whether a feature is enabled.

Primarily used with refresh and fetch methods.

interval

@return Integer

Specity interval length for a feature.

This is used primarily to keep tokens alive while a user is active on the app.