nuxt-auth-utils 0.0.18 → 0.0.20
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/README.md +3 -2
- package/dist/module.json +1 -1
- package/dist/module.mjs +13 -9
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -53,9 +53,10 @@ export default defineNuxtConfig({
|
|
|
53
53
|
NUXT_SESSION_PASSWORD=password-with-at-least-32-characters
|
|
54
54
|
```
|
|
55
55
|
|
|
56
|
-
Nuxt Auth Utils
|
|
56
|
+
Nuxt Auth Utils generates one for you when running Nuxt in development the first time if no `NUXT_SESSION_PASSWORD` is set.
|
|
57
|
+
|
|
58
|
+
3. That's it! You can now add authentication to your Nuxt app ✨
|
|
57
59
|
|
|
58
|
-
4. That's it! You can now add authentication to your Nuxt app ✨
|
|
59
60
|
|
|
60
61
|
## Vue Composables
|
|
61
62
|
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { defineNuxtModule, createResolver, addImportsDir, addPlugin, addServerHandler } from '@nuxt/kit';
|
|
2
|
-
import {
|
|
2
|
+
import { join } from 'pathe';
|
|
3
3
|
import { defu } from 'defu';
|
|
4
|
+
import { randomUUID } from 'uncrypto';
|
|
5
|
+
import { readFile, writeFile } from 'node:fs/promises';
|
|
4
6
|
|
|
5
7
|
const module = defineNuxtModule({
|
|
6
8
|
meta: {
|
|
@@ -9,14 +11,8 @@ const module = defineNuxtModule({
|
|
|
9
11
|
},
|
|
10
12
|
// Default configuration options of the Nuxt module
|
|
11
13
|
defaults: {},
|
|
12
|
-
setup(options, nuxt) {
|
|
14
|
+
async setup(options, nuxt) {
|
|
13
15
|
const resolver = createResolver(import.meta.url);
|
|
14
|
-
if (!process.env.NUXT_SESSION_PASSWORD && !nuxt.options._prepare) {
|
|
15
|
-
const randomPassword = sha256(`${Date.now()}${Math.random()}`).slice(0, 32);
|
|
16
|
-
process.env.NUXT_SESSION_PASSWORD = randomPassword;
|
|
17
|
-
console.warn("No session password set, using a random password, please set NUXT_SESSION_PASSWORD in your .env file with at least 32 chars");
|
|
18
|
-
console.log(`NUXT_SESSION_PASSWORD=${randomPassword}`);
|
|
19
|
-
}
|
|
20
16
|
nuxt.options.alias["#auth-utils"] = resolver.resolve("./runtime/types/index");
|
|
21
17
|
addImportsDir(resolver.resolve("./runtime/composables"));
|
|
22
18
|
addPlugin(resolver.resolve("./runtime/plugins/session.server"));
|
|
@@ -54,11 +50,19 @@ const module = defineNuxtModule({
|
|
|
54
50
|
const runtimeConfig = nuxt.options.runtimeConfig;
|
|
55
51
|
runtimeConfig.session = defu(runtimeConfig.session, {
|
|
56
52
|
name: "nuxt-session",
|
|
57
|
-
password: "",
|
|
53
|
+
password: process.env.NUXT_SESSION_PASSWORD || "",
|
|
58
54
|
cookie: {
|
|
59
55
|
sameSite: "lax"
|
|
60
56
|
}
|
|
61
57
|
});
|
|
58
|
+
if (nuxt.options.dev && !runtimeConfig.session.password) {
|
|
59
|
+
runtimeConfig.session.password = randomUUID().replace(/-/g, "");
|
|
60
|
+
const envPath = join(nuxt.options.rootDir, ".env");
|
|
61
|
+
const envContent = await readFile(envPath, "utf-8").catch(() => "");
|
|
62
|
+
if (!envContent.includes("NUXT_SESSION_PASSWORD")) {
|
|
63
|
+
await writeFile(envPath, `${envContent ? envContent + "\n" : envContent}NUXT_SESSION_PASSWORD=${runtimeConfig.session.password}`, "utf-8");
|
|
64
|
+
}
|
|
65
|
+
}
|
|
62
66
|
runtimeConfig.oauth = defu(runtimeConfig.oauth, {});
|
|
63
67
|
runtimeConfig.oauth.github = defu(runtimeConfig.oauth.github, {
|
|
64
68
|
clientId: "",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-auth-utils",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.20",
|
|
4
4
|
"description": "Minimalist Auth module for Nuxt with SSR",
|
|
5
5
|
"repository": "Atinux/nuxt-auth-utils",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,7 +34,9 @@
|
|
|
34
34
|
"defu": "^6.1.4",
|
|
35
35
|
"hookable": "^5.5.3",
|
|
36
36
|
"ofetch": "^1.3.3",
|
|
37
|
-
"ohash": "^1.1.3"
|
|
37
|
+
"ohash": "^1.1.3",
|
|
38
|
+
"pathe": "^1.1.2",
|
|
39
|
+
"uncrypto": "^0.1.3"
|
|
38
40
|
},
|
|
39
41
|
"devDependencies": {
|
|
40
42
|
"@iconify-json/simple-icons": "^1.1.91",
|