nuxt-auther 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +217 -0
- package/package.json +70 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 nuxt-alt
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
<h1 align="center">Auth</h1>
|
|
2
|
+
<p align="center">Alternative Auth module for Nuxt</p>
|
|
3
|
+
|
|
4
|
+
<p align="center">
|
|
5
|
+
<a href="https://www.npmjs.com/package/@nuxt-alt/auth">
|
|
6
|
+
<img alt="" src="https://img.shields.io/npm/v/@nuxt-alt/auth.svg?style=flat&colorA=18181B&colorB=28CF8D">
|
|
7
|
+
</a>
|
|
8
|
+
<a href="https://www.npmjs.com/package/@nuxt-alt/auth">
|
|
9
|
+
<img alt="" src="https://img.shields.io/npm/dt/@nuxt-alt/auth.svg?style=flat&colorA=18181B&colorB=28CF8D">
|
|
10
|
+
</a>
|
|
11
|
+
</p>
|
|
12
|
+
|
|
13
|
+
## Info
|
|
14
|
+
|
|
15
|
+
This module is meant as an alternative to @nuxtjs/auth, except this is for nuxt3 only with no backwards compatibility support.
|
|
16
|
+
|
|
17
|
+
## Setup
|
|
18
|
+
|
|
19
|
+
1. Add `@nuxt-alt/auth` and `@nuxt-alt/http` dependency to your project
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
yarn add @nuxt-alt/auth @nuxt-alt/http
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
2. Add `@nuxt-alt/auth` and `@pinia/nuxt` to the `modules` section of `nuxt.config.ts`
|
|
26
|
+
|
|
27
|
+
**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
|
|
28
|
+
it will use nuxt's `useState` by default.
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
export default defineNuxtConfig({
|
|
32
|
+
modules: [
|
|
33
|
+
'@nuxt-alt/auth'
|
|
34
|
+
],
|
|
35
|
+
auth: {
|
|
36
|
+
/* module options */
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Documentation
|
|
43
|
+
[Read Documentation](https://nuxt-alt-auth.vercel.app)
|
|
44
|
+
|
|
45
|
+
## Changes
|
|
46
|
+
|
|
47
|
+
The module now uses '@nuxt-alt/http' to function, that module extends ohmyfetch. Please note that if you were using `data` to post data, you now need to use `body` since this is what `ohmyfetch` uses. If you intend to use ssr, please consider using the `@nuxt-alt/proxy` module.
|
|
48
|
+
|
|
49
|
+
## Composable
|
|
50
|
+
|
|
51
|
+
A `useAuth()` composable is availale to use to access the auth methods.
|
|
52
|
+
|
|
53
|
+
## Options
|
|
54
|
+
Most of the options are taken directly from the [@nuxtjs/auth](https://auth.nuxtjs.org/api/options) module. In addition there are some extra options available.
|
|
55
|
+
|
|
56
|
+
### `globalMiddleware`
|
|
57
|
+
|
|
58
|
+
- Type: `Boolean`
|
|
59
|
+
- Default: `false`
|
|
60
|
+
|
|
61
|
+
Enables/disables the middleware to be used globally.
|
|
62
|
+
|
|
63
|
+
### `enableMiddleware`
|
|
64
|
+
|
|
65
|
+
- Type: `Boolean`
|
|
66
|
+
- Default: `true`
|
|
67
|
+
|
|
68
|
+
Enables/disables the built-in middleware.
|
|
69
|
+
|
|
70
|
+
### `stores.state.namespace`
|
|
71
|
+
|
|
72
|
+
- Type: `String`
|
|
73
|
+
- Default: `auth`
|
|
74
|
+
|
|
75
|
+
This is the namespace to use for nuxt useState.
|
|
76
|
+
|
|
77
|
+
### `stores.pinia.enabled`
|
|
78
|
+
- Type: `Boolean`
|
|
79
|
+
- Default: `false`
|
|
80
|
+
|
|
81
|
+
Enable this option to use the pinia store, bey default this is disabled and nuxt's `useState` is used instead.
|
|
82
|
+
|
|
83
|
+
### `stores.pinia.namespace`
|
|
84
|
+
|
|
85
|
+
- Type: `String`
|
|
86
|
+
- Default: `auth`
|
|
87
|
+
|
|
88
|
+
This is the namespace to use for the pinia store.
|
|
89
|
+
|
|
90
|
+
### `stores.local.enabled`
|
|
91
|
+
- Type: `Boolean`
|
|
92
|
+
- Default: `true`
|
|
93
|
+
|
|
94
|
+
Enable this option to use the localStorage store.
|
|
95
|
+
|
|
96
|
+
### `stores.local.prefix`
|
|
97
|
+
|
|
98
|
+
- Type: `String`
|
|
99
|
+
- Default: `auth.`
|
|
100
|
+
|
|
101
|
+
This sets the localStorage prefix.
|
|
102
|
+
|
|
103
|
+
### `stores.session.enabled`
|
|
104
|
+
- Type: `Boolean`
|
|
105
|
+
- Default: `true`
|
|
106
|
+
|
|
107
|
+
Enable this option to use the sessionStorage store.
|
|
108
|
+
|
|
109
|
+
### `stores.session.prefix`
|
|
110
|
+
|
|
111
|
+
- Type: `String`
|
|
112
|
+
- Default: `auth.`
|
|
113
|
+
|
|
114
|
+
Similar to the localstorage option, this is the prefix for session storage.
|
|
115
|
+
|
|
116
|
+
### `stores.cookie.enabled`
|
|
117
|
+
- Type: `Boolean`
|
|
118
|
+
- Default: `true`
|
|
119
|
+
|
|
120
|
+
Enable this option to use the cookie storage.
|
|
121
|
+
|
|
122
|
+
### `stores.cookie.prefix`
|
|
123
|
+
|
|
124
|
+
- Type: `String`
|
|
125
|
+
- Default: `auth.`
|
|
126
|
+
|
|
127
|
+
Similar to the localstorage option, this is the prefix for the cookie storage.
|
|
128
|
+
|
|
129
|
+
### `stores.cookie.options`
|
|
130
|
+
|
|
131
|
+
- Type: `Object`
|
|
132
|
+
- Default: `{ path: '/' }`
|
|
133
|
+
|
|
134
|
+
The default cookie storage options.
|
|
135
|
+
|
|
136
|
+
### `redirectStrategy`
|
|
137
|
+
|
|
138
|
+
- Type: `query | storage`
|
|
139
|
+
- Default: `storage`
|
|
140
|
+
|
|
141
|
+
The type of redirection strategy you want to use, `storage` utilizng localStorage for redirects, `query` utilizing the route query parameters.
|
|
142
|
+
|
|
143
|
+
### `tokenValidationInterval`
|
|
144
|
+
|
|
145
|
+
- Type: `Boolean | Number`
|
|
146
|
+
- Default: `false`
|
|
147
|
+
|
|
148
|
+
This is experimental. If set to true, default interval is 1000ms, otherwise set time in milliseconds. This is how often the module with attempt to validate the token for expiry.
|
|
149
|
+
|
|
150
|
+
### `resetOnResponseError`
|
|
151
|
+
|
|
152
|
+
- Type: `Boolean | Function`
|
|
153
|
+
- Default: `false`
|
|
154
|
+
|
|
155
|
+
When enabled it will reset when there's a 401 error in any of the responses. You are able to turn this into a function to handle this yourself:
|
|
156
|
+
```ts
|
|
157
|
+
auth: {
|
|
158
|
+
//... module options
|
|
159
|
+
resetOnResponseError: (error, auth, scheme) => {
|
|
160
|
+
if (error.response.status === 401) {
|
|
161
|
+
scheme.reset?.()
|
|
162
|
+
auth.redirect('login')
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
}
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## TypeScript (2.6.0+)
|
|
169
|
+
The user information can be edited like so for TypeScript:
|
|
170
|
+
```ts
|
|
171
|
+
declare module '@nuxt-alt/auth' {
|
|
172
|
+
interface UserInfo {
|
|
173
|
+
email: string
|
|
174
|
+
name: string
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
## Tokens (Types)
|
|
180
|
+
|
|
181
|
+
In addition to [Auth Tokens](https://auth.nuxtjs.org/api/tokens);
|
|
182
|
+
|
|
183
|
+
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.
|
|
184
|
+
|
|
185
|
+
## Oauth2
|
|
186
|
+
|
|
187
|
+
Oauth2 now has client window authentication thanks to this pull request: https://github.com/nuxt-community/auth-module/pull/1746
|
|
188
|
+
|
|
189
|
+
Properties have been changed to:
|
|
190
|
+
|
|
191
|
+
### `clientWindow`
|
|
192
|
+
|
|
193
|
+
- Type: `Boolean`
|
|
194
|
+
- Default: `false`
|
|
195
|
+
|
|
196
|
+
Enable/disable the use of a popup for client authentication.
|
|
197
|
+
|
|
198
|
+
### `clientWidth`
|
|
199
|
+
|
|
200
|
+
- Type: `Number`
|
|
201
|
+
- Default: `400`
|
|
202
|
+
|
|
203
|
+
The width of the client window.
|
|
204
|
+
|
|
205
|
+
### `clientHieght`
|
|
206
|
+
|
|
207
|
+
- Type: `Number`
|
|
208
|
+
- Default: `600`
|
|
209
|
+
|
|
210
|
+
The width of the client window.
|
|
211
|
+
|
|
212
|
+
## Aliases
|
|
213
|
+
Available aliases to use within nuxt
|
|
214
|
+
|
|
215
|
+
- `#auth/runtime`
|
|
216
|
+
- `#auth/utils`
|
|
217
|
+
- `#auth/providers`
|
package/package.json
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "nuxt-auther",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Authentication module for Nuxt.JS",
|
|
5
|
+
"homepage": "https://github.com/zerosdev/nuxt-auther",
|
|
6
|
+
"author": "zerosdev",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"auth",
|
|
9
|
+
"nuxt",
|
|
10
|
+
"nuxt3",
|
|
11
|
+
"nuxtjs",
|
|
12
|
+
"nuxt-module",
|
|
13
|
+
"nuxt-plugin",
|
|
14
|
+
"@nuxtjs/auth",
|
|
15
|
+
"@nuxt-alt/auth"
|
|
16
|
+
],
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"type": "module",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/types/index.d.ts",
|
|
22
|
+
"import": "./dist/module.mjs",
|
|
23
|
+
"require": "./dist/module.cjs"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"main": "./dist/module.cjs",
|
|
27
|
+
"module": "./dist/module.mjs",
|
|
28
|
+
"types": "./dist/types/index.d.ts",
|
|
29
|
+
"files": [
|
|
30
|
+
"dist"
|
|
31
|
+
],
|
|
32
|
+
"scripts": {
|
|
33
|
+
"dev": "nuxi dev playground",
|
|
34
|
+
"dev:build": "nuxi build playground"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@nuxt-alt/http": "latest",
|
|
38
|
+
"@nuxt/kit": "^3.12.2",
|
|
39
|
+
"@refactorjs/serialize": "latest",
|
|
40
|
+
"cookie-es": "^1.1.0",
|
|
41
|
+
"defu": "^6.1.3",
|
|
42
|
+
"jwt-decode": "^4.0.0",
|
|
43
|
+
"ohash": "^1.1.3",
|
|
44
|
+
"pathe": "^1.1.2",
|
|
45
|
+
"pinia": "^2.1.7",
|
|
46
|
+
"requrl": "^3.0.2"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@nuxt-alt/proxy": "^2.5.8",
|
|
50
|
+
"@nuxt/schema": "^3.12.2",
|
|
51
|
+
"@nuxtjs/i18n": "next",
|
|
52
|
+
"@types/node": "^20",
|
|
53
|
+
"jiti": "^1.21.6",
|
|
54
|
+
"nuxt": "^3.9.3",
|
|
55
|
+
"typescript": "5.3.3",
|
|
56
|
+
"unbuild": "^2.0.0"
|
|
57
|
+
},
|
|
58
|
+
"repository": {
|
|
59
|
+
"type": "git",
|
|
60
|
+
"url": "git+https://github.com/zerosdev/nuxt-auther.git",
|
|
61
|
+
"directory": "nuxt-auther"
|
|
62
|
+
},
|
|
63
|
+
"bugs": {
|
|
64
|
+
"url": "https://github.com/zerosdev/nuxt-auther/issues"
|
|
65
|
+
},
|
|
66
|
+
"publishConfig": {
|
|
67
|
+
"access": "public"
|
|
68
|
+
},
|
|
69
|
+
"packageManager": "yarn@4.9.2"
|
|
70
|
+
}
|