Skip to content

Commit

Permalink
v3.0.0 (#79)
Browse files Browse the repository at this point in the history
* Auth Refactor

- Changed storage reliance on pinia:

Pinia is no longer required to use the auth module, but can still be used. By default it is disabled and instead nuxt's useState will be used instead.

- Moved login watch to plugin:

This is still in testing however I found that watching loggedIn works better when it's in a plugin.

- Consolidated store/storage options:

localStorage, sessionStorage, cookie, and pinia have all been moved under on property called 'stores'. Theves also been shortened in name so localStorage is 'local', cookie is 'cookie', and sessionStorage is 'session'.

The strategy cookie, will no longer be present if you're not logged in.

The syncUniversal/setUniversal now accept a third object parameter that dictates whether or not you want to exclude a store (the store wont be added in any case if its disabled in your options). In the case for cookies you can either use a boolean or an object which contains the cookie's options.

* Cookie Scheme Refactor

 - The Cookie scheme has been added back under the local scheme. It still retains the same functionality if you're not using the token property.

-  The Laravel Sanctum provider will use the token method, if you'd like to use the  SPA method set token.type to false.

 - Documentation stackblitz has been update to reflect changes: https://stackblitz.com/edit/github-nufjhw?file=README.md

* Improve type support

- When configuring the auth options the strategies would have no type hinting. This update aims to fix this.

* preparation: v3.0.0 Release
  • Loading branch information
Denoder authored Nov 23, 2023
1 parent 87da58b commit 8e805fe
Show file tree
Hide file tree
Showing 34 changed files with 696 additions and 436 deletions.
60 changes: 52 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,56 @@
# Dependencies
node_modules
*.iml
.idea

# Logs
*.log*

# Temp directories
.temp
.tmp
.cache

# Yarn
**/.yarn/cache
**/.yarn/*state*

# Generated dirs
dist

# Nuxt
.nuxt
.vscode
.DS_STORE
.output
.data
.vercel_build_output
.build-*
.netlify

# Env
.env

# Testing
reports
coverage
dist
package-lock.json
temp
tsdoc-metadata.json
*.lcov
.nyc_output

# VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/*.code-snippets

# Intellij idea
*.iml
.idea

# OSX
.DS_Store
.AppleDouble
.LSOverride
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
7 changes: 7 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
compressionLevel: mixed

enableGlobalCache: false

nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-4.0.2.cjs
96 changes: 71 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
> Alternative Auth module for [Nuxt](https://nuxt.com)
<h1 align="center">Auth</h1>
<p align="center">Alternative Auth module for Nuxt</p>

<p align="center">
<a href="https://www.npmjs.com/package/@nuxt-alt/auth">
<img alt="" src="https://img.shields.io/npm/v/@nuxt-alt/auth.svg?style=flat&colorA=18181B&colorB=28CF8D">
</a>
<a href="https://www.npmjs.com/package/@nuxt-alt/auth">
<img alt="" src="https://img.shields.io/npm/dt/@nuxt-alt/auth.svg?style=flat&colorA=18181B&colorB=28CF8D">
</a>
</p>

## Info

This module is meant as an alternative to @nuxtjs/auth, except this is for nuxt3 only with no backwards compatibility support. This will only work with pinia, I had originally had it work with vuex, but since that is in maintenece mode, I decided to switch to pinia. If you find any bugs please do tell me, I'm still working on this.
This module is meant as an alternative to @nuxtjs/auth, except this is for nuxt3 only with no backwards compatibility support.

## Setup

Expand All @@ -14,7 +24,8 @@ yarn add @nuxt-alt/auth @nuxt-alt/http @pinia/nuxt pinia

2. Add `@nuxt-alt/auth` and `@pinia/nuxt` to the `modules` section of `nuxt.config.ts`

**Note:** you dont need to specify `@nuxt-alt/http`, it will automatically be added but if you want to manually add it, make sure it is below the auth module (and above the proxy module if you are using it)
**Note:** you dont need to specify `@nuxt-alt/http`, it will automatically be added but if you want to manually add it, make sure it is below the auth module (and above the proxy module if you are using it). It also doesn't need pinia
it will use nuxt's `useState` by default.

```ts
export default defineNuxtConfig({
Expand Down Expand Up @@ -54,52 +65,81 @@ Enables/disables the middleware to be used globally.

Enables/disables the built-in middleware.

### `pinia.namespace`
### `stores.state.namespace`

- Type: `String`
- Default: `auth`

Changed from vuex to pinia, this is the namespace to use for the pinia store.
This is the namespace to use for nuxt useState.

### `sessionStorage`
### `stores.pinia.enabled`
- Type: `Boolean`
- Default: `false`

Enable this option to use the pinia store, bey default this is disabled and nuxt's `useState` is used instead.

### `stores.pinia.namespace`

- Type: `String`
- Default: `auth`

This is the namespace to use for the pinia store.

### `stores.local.enabled`
- Type: `Boolean`
- Default: `true`

- Type: `String | False`
Enable this option to use the localStorage store.

### `stores.local.prefix`

- Type: `String`
- Default: `auth.`

Similar to the localstorage option, there is a session storage options available for you to use.
This sets the localStorage prefix.

### `routerStrategy`
### `stores.session.enabled`
- Type: `Boolean`
- Default: `true`

- Type: `router | navigateTo`
- Default: `router`
Enable this option to use the sessionStorage store.

By default it will use `router` (`navigateTo` has an issue; I'm assuming with SSR that I don't have the time to check into at the moment, but I'll eventually want to replace with at some point.)
### `stores.session.prefix`

### `redirectStrategy`
- Type: `String`
- Default: `auth.`

- Type: `query | storage`
- Default: `storage`
Similar to the localstorage option, this is the prefix for session storage.

The type of redirection strategy you want to use, `storage` utilizng localStorage for redirects, `query` utilizing the route query parameters.
### `stores.cookie.enabled`
- Type: `Boolean`
- Default: `true`

## Tokens (Types)
Enable this option to use the cookie storage.

In addition to [Auth Tokens](https://auth.nuxtjs.org/api/tokens);
### `stores.cookie.prefix`

By default the `$auth.strategy` getter uses the `Scheme` type which does not have `token` or `refreshToken` property types. To help with this, a `$auth.refreshStrategy` and a `$auth.tokenStrategy` getter have been added for typing. They all do the same thing, this is just meant for type hinting.
- Type: `String`
- Default: `auth.`

## Cookie-based auth (Update: 2.5.0+)
Similar to the localstorage option, this is the prefix for the cookie storage.

The cookie scheme has been decoupled from the local scheme as it does not utitlize tokens, rather it it uses cookies.
### `stores.cookie.options`

~~There is a new `cookie.server` property, this indicates that the cookie we will be looking for will be set upon login otherwise we will be looking at a client/browser cookie. There has also been 2 user properties one for the client/browser and one for the server. An example config looks like this:~~
- Type: `Object`
- Default: `{ path: '/' }`

The `cookie.server` param has been removed. This was meant as a workaround to decouple the server and client user request when logging in because the check was being overriden. This should be fixed in 2.5.0. The `user.property` param no longer needs to be separated by server and client so use `user.property` instead of `user.property.server` and `user.property.client`.
The default cookie storage options.

## TypeScript (2.6.0+)
### `redirectStrategy`

The user information can be edited like so for TypeScript:
- Type: `query | storage`
- Default: `storage`

The type of redirection strategy you want to use, `storage` utilizng localStorage for redirects, `query` utilizing the route query parameters.

## TypeScript (2.6.0+)
The user information can be edited like so for TypeScript:
```ts
declare module '@nuxt-alt/auth' {
interface UserInfo {
Expand All @@ -109,6 +149,12 @@ declare module '@nuxt-alt/auth' {
}
```

## Tokens (Types)

In addition to [Auth Tokens](https://auth.nuxtjs.org/api/tokens);

By default the `$auth.strategy` getter uses the `Scheme` type which does not have `token` or `refreshToken` property types. To help with this, a `$auth.refreshStrategy` and a `$auth.tokenStrategy` getter have been added for typing. They all do the same thing, this is just meant for type hinting.

## Oauth2

Oauth2 now has client window authentication thanks to this pull request: https://github.com/nuxt-community/auth-module/pull/1746
Expand Down
91 changes: 0 additions & 91 deletions build.config.ts

This file was deleted.

Loading

0 comments on commit 8e805fe

Please sign in to comment.