nuxt-users 1.14.0 → 1.15.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/CHANGELOG.md CHANGED
@@ -1,6 +1,27 @@
1
1
  # Changelog
2
2
 
3
3
 
4
+ ## v1.15.0
5
+
6
+ [compare changes](https://github.com/rrd108/nuxt-users/compare/v1.14.0...v1.15.0)
7
+
8
+ ### 🚀 Enhancements
9
+
10
+ - Add getCurrentUser utility ([0096fb2](https://github.com/rrd108/nuxt-users/commit/0096fb2))
11
+
12
+ ### 💅 Refactors
13
+
14
+ - GetCurrentUser from a utility to a composable ([10149d2](https://github.com/rrd108/nuxt-users/commit/10149d2))
15
+
16
+ ### 🏡 Chore
17
+
18
+ - **release:** V1.14.0 ([6c32154](https://github.com/rrd108/nuxt-users/commit/6c32154))
19
+ - Fix whitespace ([517d60d](https://github.com/rrd108/nuxt-users/commit/517d60d))
20
+
21
+ ### ❤️ Contributors
22
+
23
+ - Rrd108 ([@rrd108](https://github.com/rrd108))
24
+
4
25
  ## v1.14.0
5
26
 
6
27
  [compare changes](https://github.com/rrd108/nuxt-users/compare/v1.13.0...v1.14.0)
package/dist/cli.mjs CHANGED
@@ -247,7 +247,7 @@ const main = defineCommand({
247
247
  meta: {
248
248
  name: "nuxt-users",
249
249
  description: "CLI for Nuxt Users Module - Manage users, migrations, and database operations",
250
- version: "1.13.0"
250
+ version: "1.14.0"
251
251
  },
252
252
  subCommands: {
253
253
  migrate,
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxt-users",
3
3
  "configKey": "nuxtUsers",
4
- "version": "1.14.0",
4
+ "version": "1.15.0",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.0"
@@ -0,0 +1,5 @@
1
+ import { type H3Event } from 'h3';
2
+ import type { UserWithoutPassword } from '../../types.js';
3
+ export declare const useServerAuth: () => {
4
+ getCurrentUser: (event: H3Event) => Promise<UserWithoutPassword | null>;
5
+ };
@@ -0,0 +1,17 @@
1
+ import { getCurrentUserFromToken } from "../server/utils/user.js";
2
+ import { useRuntimeConfig } from "#imports";
3
+ import { getCookie } from "h3";
4
+ const getCurrentUser = async (event) => {
5
+ const token = getCookie(event, "auth_token");
6
+ if (!token) {
7
+ return null;
8
+ }
9
+ const { nuxtUsers } = useRuntimeConfig();
10
+ const user = await getCurrentUserFromToken(token, nuxtUsers, false);
11
+ return user;
12
+ };
13
+ export const useServerAuth = () => {
14
+ return {
15
+ getCurrentUser
16
+ };
17
+ };
@@ -1,5 +1,5 @@
1
1
  export { useDb, checkTableExists } from './db.js';
2
- export { createUser, findUserByEmail, updateUserPassword, getCurrentUserFromToken, getCurrentUser, hasAnyUsers, deleteExpiredPersonalAccessTokens, deleteTokensWithoutExpiration, cleanupPersonalAccessTokens, revokeUserTokens, getLastLoginTime } from './user.js';
2
+ export { createUser, findUserByEmail, updateUserPassword, getCurrentUserFromToken, hasAnyUsers, deleteExpiredPersonalAccessTokens, deleteTokensWithoutExpiration, cleanupPersonalAccessTokens, revokeUserTokens, getLastLoginTime } from './user.js';
3
3
  export { createUsersTable } from './create-users-table.js';
4
4
  export { createPersonalAccessTokensTable } from './create-personal-access-tokens-table.js';
5
5
  export { createPasswordResetTokensTable } from './create-password-reset-tokens-table.js';
@@ -1,5 +1,5 @@
1
1
  export { useDb, checkTableExists } from "./db.js";
2
- export { createUser, findUserByEmail, updateUserPassword, getCurrentUserFromToken, getCurrentUser, hasAnyUsers, deleteExpiredPersonalAccessTokens, deleteTokensWithoutExpiration, cleanupPersonalAccessTokens, revokeUserTokens, getLastLoginTime } from "./user.js";
2
+ export { createUser, findUserByEmail, updateUserPassword, getCurrentUserFromToken, hasAnyUsers, deleteExpiredPersonalAccessTokens, deleteTokensWithoutExpiration, cleanupPersonalAccessTokens, revokeUserTokens, getLastLoginTime } from "./user.js";
3
3
  export { createUsersTable } from "./create-users-table.js";
4
4
  export { createPersonalAccessTokensTable } from "./create-personal-access-tokens-table.js";
5
5
  export { createPasswordResetTokensTable } from "./create-password-reset-tokens-table.js";
@@ -61,25 +61,4 @@ export declare const revokeUserTokens: (userId: number, options: ModuleOptions)
61
61
  * This represents when the user last successfully logged in.
62
62
  */
63
63
  export declare const getLastLoginTime: (userId: number, options: ModuleOptions) => Promise<string | null>;
64
- /**
65
- * Gets the current authenticated user from an H3Event.
66
- * Handles token extraction and user lookup automatically.
67
- *
68
- * @example
69
- * ```typescript
70
- * // server/api/example.get.ts
71
- * import { getCurrentUser } from 'nuxt-users/server'
72
- *
73
- * export default defineEventHandler(async (event) => {
74
- * const user = await getCurrentUser(event)
75
- *
76
- * if (!user) {
77
- * throw createError({ statusCode: 401, statusMessage: 'Unauthorized' })
78
- * }
79
- *
80
- * return { message: `Hello ${user.name}!` }
81
- * })
82
- * ```
83
- */
84
- export declare const getCurrentUser: (event: any) => Promise<UserWithoutPassword | null>;
85
64
  export {};
@@ -213,14 +213,3 @@ export const getLastLoginTime = async (userId, options) => {
213
213
  const lastLogin = result.rows[0].created_at;
214
214
  return lastLogin instanceof Date ? lastLogin.toISOString() : lastLogin;
215
215
  };
216
- export const getCurrentUser = async (event) => {
217
- const { getCookie } = await import("h3");
218
- const { useRuntimeConfig } = await import("#imports");
219
- const token = getCookie(event, "auth_token");
220
- if (!token) {
221
- return null;
222
- }
223
- const { nuxtUsers } = useRuntimeConfig();
224
- const user = await getCurrentUserFromToken(token, nuxtUsers, false);
225
- return user;
226
- };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-users",
3
- "version": "1.14.0",
3
+ "version": "1.15.0",
4
4
  "description": "A comprehensive user management module for Nuxt 3 and Nuxt 4 applications with authentication, authorization, database support, and CLI tools",
5
5
  "keywords": [
6
6
  "nuxt",