@witchcraft/nuxt-auth 0.0.2 → 0.1.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/README.md CHANGED
@@ -35,11 +35,20 @@ It is highly recommended you install the nuxt-security module (or something simi
35
35
  pnpx nuxi module add nuxt-security
36
36
  ```
37
37
 
38
- The module requires the `@witchcraft/ui` module for ui components but is otherwise optional.
38
+ The module requires the `@witchcraft/ui` module for ui components but those are optional so it's not needed if you won't be using them.
39
+
39
40
  ```bash
40
41
  pnpx nuxi module add @witchcraft/ui
41
42
  ```
42
43
 
44
+ `@witchcraft/nuxt-logger` is also recommended as it includes redaction for the redact property, otherwise **you will have to implement this yourself**.
45
+ All logs are objects with at least an `ns` (namespace) property and can ocassionally contain a `redact` property that **must be redacted in production to be secure**.
46
+
47
+ ```bash
48
+ pnpx nuxi module add @witchcraft/nuxt-logger
49
+
50
+ ```
51
+ Don't forget to actually pass it's `useServerLogger` when creating the apis.
43
52
 
44
53
  ## Usage
45
54
 
@@ -126,7 +135,7 @@ Then create two files:
126
135
  This creates the api handler.
127
136
  ```ts [server/api/auth/[...].ts]
128
137
 
129
- import { createAuthHandler } from "#imports"
138
+ import { createAuthHandler, useServerLogger } from "#imports"
130
139
  import { authAccounts, users } from "~~/db/schema.js"
131
140
  import { db } from "[PATH TO YOUR DRIZZLE DB]"
132
141
  import { sessionManager } from "[PATH TO YOUR SESSION MANAGER INSTANCE]"
@@ -136,7 +145,9 @@ export default createAuthHandler(
136
145
  db,
137
146
  users,
138
147
  authAccounts,
139
- sessionManager, {
148
+ sessionManager,
149
+ useServerLogger(),
150
+ {
140
151
  onRegister: (event, route, deeplink) => {
141
152
  // handle user registration, deeplink is for when using external auth handlers (see below)
142
153
  }
@@ -151,10 +162,13 @@ This creates the middleware that sets the user/session on the request context.
151
162
  ```ts
152
163
  // server/middleware/auth.ts
153
164
 
154
- import { createAuthMiddleware } from "#imports"
165
+ import { createAuthMiddleware, useServerLogger } from "#imports"
155
166
 
156
167
  import { sessionManager } from "[PATH TO YOUR SESSION MANAGER INSTANCE]"
157
- export default createAuthMiddleware(sessionManager)
168
+ export default createAuthMiddleware(
169
+ sessionManager,
170
+ useServerLogger()
171
+ )
158
172
  ```
159
173
 
160
174
  ### Create the Pages
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "auth",
3
3
  "configKey": "auth",
4
- "version": "0.0.1",
4
+ "version": "0.0.2",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
@@ -5,4 +5,4 @@ import type { RuntimeConfig } from "nuxt/schema";
5
5
  import type { AuthAccountsTable, UserTable } from "./createAuthSchema.js.js";
6
6
  import type { SessionManager } from "./SessionManager.js.js";
7
7
  import type { AuthHandlerOptions } from "../../types.js.js";
8
- export declare function createAuthHandler(rc: RuntimeConfig, db: PgDatabase<any, any, any>, usersTable: UserTable, authAccountsTable: AuthAccountsTable, sessionManager: SessionManager, opts?: Partial<AuthHandlerOptions>, logger?: BaseLogger): EventHandler;
8
+ export declare function createAuthHandler(rc: RuntimeConfig, db: PgDatabase<any, any, any>, usersTable: UserTable, authAccountsTable: AuthAccountsTable, sessionManager: SessionManager, logger: BaseLogger, opts?: Partial<AuthHandlerOptions>): EventHandler;
@@ -2,7 +2,7 @@ import { Auth } from "./Auth.js";
2
2
  import github from "#auth/core/providers/github.js";
3
3
  import google from "#auth/core/providers/google.js";
4
4
  import { createRouter } from "#imports";
5
- export function createAuthHandler(rc, db, usersTable, authAccountsTable, sessionManager, opts = {}, logger = console) {
5
+ export function createAuthHandler(rc, db, usersTable, authAccountsTable, sessionManager, logger, opts = {}) {
6
6
  const router = createRouter();
7
7
  const auth = new Auth(
8
8
  rc,
@@ -1,7 +1,7 @@
1
1
  import type { BaseLogger } from "@witchcraft/nuxt-logger/createUseLogger";
2
2
  import type { SessionManager } from "./SessionManager.js.js";
3
3
  import type { AuthSession, AuthUser } from "../../types.js.js";
4
- export declare function createAuthMiddleware(sessionManager: SessionManager, logger?: BaseLogger): any;
4
+ export declare function createAuthMiddleware(logger: BaseLogger, sessionManager: SessionManager): any;
5
5
  declare module "h3" {
6
6
  interface H3EventContext {
7
7
  user: AuthUser | null;
@@ -1,5 +1,5 @@
1
1
  import { defineEventHandler, getCookie, setCookie } from "#imports";
2
- export function createAuthMiddleware(sessionManager, logger = console) {
2
+ export function createAuthMiddleware(logger, sessionManager) {
3
3
  return defineEventHandler(async (event) => {
4
4
  const sessionId = getCookie(event, sessionManager.options.sessionCookie.name) ?? null;
5
5
  if (!sessionId) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@witchcraft/nuxt-auth",
3
- "version": "0.0.2",
3
+ "version": "0.1.0",
4
4
  "description": "Nuxt module for logging.",
5
5
  "repository": "witchcraftjs/nuxt-auth",
6
6
  "license": "MIT",