Giter VIP home page Giter VIP logo

nuxt-3-auth's Introduction

Nuxt 3 auth Module

npm version npm downloads License Nuxt

A simple authentication module for Nuxt 3

Features

  • 🤝  Compatible with pinia, nuxtjs/i18n, ofetch.
  • 🚀  Built in pages and compositions.
  • ⚙️  Support refresh tokens

Quick Setup

  1. Add @trandaison/nuxt-3-auth dependency to your project
# Using pnpm
pnpm add -D @trandaison/nuxt-3-auth

# Using yarn
yarn add --dev @trandaison/nuxt-3-auth

# Using npm
npm install --save-dev @trandaison/nuxt-3-auth
  1. Add @trandaison/nuxt-3-auth to the modules section of nuxt.config.ts
export default defineNuxtConfig({
  modules: [
    '@trandaison/nuxt-3-auth'
  ]
})

That's it! You can now use Nuxt 3 auth Module in your Nuxt app ✨

Development

# Install dependencies
npm install

# Generate type stubs
npm run dev:prepare

# Develop with the playground
npm run dev

# Build the playground
npm run dev:build

# Run ESLint
npm run lint

# Run Vitest
npm run test
npm run test:watch

# Release new version
npm run release

nuxt-3-auth's People

Contributors

danielroe avatar kiettl1-nals avatar trandaison avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

nuxt-3-auth's Issues

Invalid token

Any suggestion what could cause of getting this error message?
It seems it's related to refresh token, but I'm not getting why jwtDecode is trying to decode refresh_token.

Invalid token specified: missing part #2
image

refreshToken and maxAge

I see that only for JWT tokens this package will look at exp value otherwise we need to set it ourselves. Is it possible somehow to set/change programaticali after login? I get expiresAt data from some API and would like to set the maxAge of refreshToken to expiresAt - 30 seconds, so I can call refresh before it actually expires. I need to make user's token not to expire in case someone is entering data/text on a page too long.

Auto-Logout on API Retry Error

We are encountering an issue when making API calls after successfully refreshing the token. Upon completing the token refresh process, we proceeded to call the previous API again but encountered an unexpected error. The system redirected users back to the login page.

This issue is causing a disruption to the user experience and requires intervention to resolve.

Value is missing on SSR

Can you please clarify why I can't get loggedIn.value on SSR is this intended behaviour?

here is how my code looks like:

  const { $auth } = useNuxtApp()
  const { user, loggedIn } = $auth

  if (import.meta.server) {
    console.log(`🆘 ~ SERVER loggedIn:`, loggedIn)
    console.log(`🆘 ~ SERVER loggedIn:`, loggedIn.value)
  }

  if (import.meta.client) {
    console.log(`🆘 ~ CLIENT loggedIn:`, loggedIn)
    console.log(`🆘 ~ CLIENT loggedIn:`, loggedIn.value)
  }

And here is the result:
SSR:
image

CLIENT:
image

Feat: Support any type of token

Describe the feature

There is a limitation so far, it requires to use jwt tokens (also mentioned on the docs). If your token is not a jwt one will cause this error.

Proposal

Add 2 more options token.maxAge and refreshToken.maxAge to specific the cookie maxAge for access token and refresh token if tokens are not JWT.

Related issue

#16

Disable the built-in /login?

Is it possible to somehow completely remove the /login from package? I have the same route and would like to use my own form that is styled like the rest of website.

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.