Git Product home page Git Product logo

quasar-app-extension-http-authentication's Introduction

Quasar App Extension - Http Authentication

This app extension provides http authentication functionality by using a Vuex store.

Dependencies

Both axios as well as Vuex are required for this extension.

Install

quasar ext add http-authentication

Quasar CLI will retrieve it from NPM and install the extension.

Prompts

The installation prompts for the routes which should be used to communicate with the backend. The requests and responses of the server should match with this extension.

There are multiple authentication schemes (https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication). This app extension was originally created for the Bearer scheme.

Layout

The extension comes with a basic menu for login, register and logout actions. Have a look at the test app.

Functionality

The authentication logic is performed inside a Vuex store. this.$auth provides a helper to access the functionality in the store.

Function Functionality
$auth.register(data) Makes a POST request to the registration route with data as body
$auth.login(data) Makes a POST request to the login route with data as body. Saves the returned token in a cookie
$auth.logout() Logs out the current user and removes the Authorixation cookie
$auth.verify(token) Makes a GET request to the verification route with token as URL parameter
$auth.passwordForgot(data) Makes a POST request to the password forgot route with data as body.
$auth.passwordReset(data) Makes a POST request to the password reset route with data as body.
$auth.loggedIn() Returns a boolean to determine if the user is logged in.
auth.check(roles) Checks if the user belongs to roles by checking if they are included in user.roles.
$auth.setToken(token) Sets the Authorization header depending on the used scheme.
$auth.fetch() Fetch the user belonging to the Authorization token from the backend
$auth.user() Returns the current user.

If you require the user object to have a specific structure or you need to perform an action upon logging in you can use the following in the prefetch function of App.vue:

/**
 * Custom user data
 */
store.commit('auth/setUserData', (data) => { return { id: data.id } })

/**
 * Login callbacks
 */
store.commit('auth/addLoginCallback', () => console.log('Custom login calback'))

Have a look at the pages to see how the functions are used internally.

Notes

Note that an existing axios boot file will be overwritten. If you require support for additional http authentication schemes, please open an issue.

Currently both a .ts and .js file is rendered into your app. You will have to delete the one which is not used in your application.

Uninstall

quasar ext remove http-authentication

Contribute

PR's for extra languages are appreciated (src/components/lang).

Donate

If you appreciate the work that went into this App Extension, please consider donating to Quasar.

quasar-app-extension-http-authentication's People

Contributors

machadoug avatar stefanvanherwijnen avatar ttquoccuong avatar

Watchers

 avatar

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.