Giter Club home page Giter Club logo

nuauth's Introduction

NuAuth

Oauth2 Client for Nuxt

Compabilities

  • Nuxt 3

Instalation

yarn add --dev @privyid/nuauth

Then, add into nuxt.config.ts modules

export default defineNuxtConfig({
  modules: ['@privyid/nuauth/module'],
})

Usage

import { useNuAuth } from '@privyid/nuauth'

const {
  token,
  isAlmostExpired,
  login,
  logout,
  refresh,
} = useNuAuth()

// Get Access-Token
token.value

// Redirect to login page
login()

// Redirect to login page, and redirect to /dashboard after success
login('/dashboard')

// Redirect to logout page
logout()

// Redirect to logout page, and redirect to /dashboard after success re-login
login('/dashboard')

// Check token is almost expired (15 minutes before Expired Date)
if (isAlmostExpired(15)) {
  // Request new token
  await refresh()
}

Configuration

This module has no configuration, instead this module read enviroment variables directly.

Env Name Default Description
OAUTH_HOST - (Required) Oauth server's host
OAUTH_CLIENT_ID - (Required) Oauth Client ID
OAUTH_CLIENT_SECRET - (Required) Oauth Client Secret
OAUTH_REDIRECT_URI - (Required) Oauth Callback URI
OAUTH_SCOPE public read Oauth scope
OAUTH_LOGOUT_URI - Oauth Logout URI
OAUTH_HOME / Redirect path after success login
OAUTH_REGISTER false Add params register to Oauth Server
OAUTH_REDIRECT_WHITELIST - Redirect path after success login whitelist, for multiple value, use ; as delimeter

See .env.example for example

Contribution

  • Clone this repository
  • Play Nyan Cat in the background (really important!)
  • Enable Corepack using corepack enable (use npm i -g corepack for Node.js < 16.10)
  • Run yarn install
  • Run yarn dev:prepare to generate type stubs.
  • Use yarn dev to start playground in development mode.

License

MIT License

nuauth's People

Contributors

adenvt avatar renovate[bot] 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.