0.0.1 • Published 6 years ago

@dysfunctionl/adonis-auth-extra v0.0.1

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

Adonis Auth Extra

A light extension of Adonis auth to add viewtags (@auth/@guest) and middleware for redirecting if authenticated.


Contents


Setup

Install

adonis install @dysfunctionl/adonis-auth-extra

Register the provider inside start/app.js file

const providers = [
  '@dysfunctionl/adonis-auth-extra/providers/AuthExtraProvider'
]

Start the server

adonis serve --dev

Config

The configuration is saved inside config/auth-extra.js file. Tweak it accordingly.

'use strict'

module.exports = {
  'middleware': {
    // Defualt URL To redirect authenticated users to
    'guestRedirect': '/home',

    // Send current request params to the redirected request
    'forwardRequestParams': false,

    // Status code to send with the redirect
    'statusCode': 302
  }
}

Usage

Middleware

// Will redirect to url in config
Route.get('/', ()=>{})
    .middleware(['guest'])

// Wil redirect to /home
Route.get('/', ()=>{})
    .middleware(['guest:/home'])

Views

@Guest
@guest
    // User is guest
@else
    // User is authenticated
@endguest

@Auth
@auth
    // User is authenticated
@else
    // User is guest
@endauth