nuxt-users 1.6.0 → 1.6.1

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,26 @@
1
1
  # Changelog
2
2
 
3
3
 
4
+ ## v1.6.1
5
+
6
+ [compare changes](https://github.com/rrd108/nuxt-users/compare/v1.6.0...v1.6.1)
7
+
8
+ ### 🩹 Fixes
9
+
10
+ - Exports `getCurrentUserFromToken` from utils index ([5c67e24](https://github.com/rrd108/nuxt-users/commit/5c67e24))
11
+
12
+ ### 💅 Refactors
13
+
14
+ - Move file to one level up ([e9111c0](https://github.com/rrd108/nuxt-users/commit/e9111c0))
15
+
16
+ ### 🏡 Chore
17
+
18
+ - **release:** V1.6.0 ([1c9eab4](https://github.com/rrd108/nuxt-users/commit/1c9eab4))
19
+
20
+ ### ❤️ Contributors
21
+
22
+ - Rrd108 ([@rrd108](https://github.com/rrd108))
23
+
4
24
  ## v1.6.0
5
25
 
6
26
  [compare changes](https://github.com/rrd108/nuxt-users/compare/v1.5.0...v1.6.0)
package/dist/cli.mjs CHANGED
@@ -2,7 +2,7 @@
2
2
  import { defineCommand, runMain } from 'citty';
3
3
  import 'db0';
4
4
  import 'bcrypt';
5
- import { r as runMigrations, i as getPasswordValidationOptions, v as validatePassword, a as createUser$1, d as createUsersTable$1, e as createPersonalAccessTokensTable$1, g as createPasswordResetTokensTable$1, h as createMigrationsTable$1 } from './shared/nuxt-users.37k1R3_g.mjs';
5
+ import { r as runMigrations, j as getPasswordValidationOptions, v as validatePassword, a as createUser$1, d as createUsersTable$1, e as createPersonalAccessTokensTable$1, h as createPasswordResetTokensTable$1, i as createMigrationsTable$1 } from './shared/nuxt-users.C_UkhLJ9.mjs';
6
6
  import { defaultOptions } from './module.mjs';
7
7
  import { loadNuxt } from '@nuxt/kit';
8
8
  import 'defu';
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxt-users",
3
3
  "configKey": "nuxtUsers",
4
- "version": "1.6.0",
4
+ "version": "1.6.1",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.1",
7
7
  "unbuild": "3.6.0"
@@ -1,6 +1,6 @@
1
1
  import { createError, defineEventHandler, getCookie } from "h3";
2
2
  import { useRuntimeConfig } from "#imports";
3
- import { getCurrentUserFromToken } from "../../../utils/user";
3
+ import { getCurrentUserFromToken } from "../../../utils";
4
4
  export default defineEventHandler(async (event) => {
5
5
  const { nuxtUsers } = useRuntimeConfig();
6
6
  const options = nuxtUsers;
@@ -269,6 +269,27 @@ const updateUserPassword = async (email, newPassword, options) => {
269
269
  WHERE email = ${email}
270
270
  `;
271
271
  };
272
+ const getCurrentUserFromToken = async (token, options) => {
273
+ const db = await useDb(options);
274
+ const personalAccessTokensTable = options.tables.personalAccessTokens;
275
+ const usersTable = options.tables.users;
276
+ const tokenResult = await db.sql`
277
+ SELECT tokenable_id FROM {${personalAccessTokensTable}}
278
+ WHERE token = ${token}
279
+ `;
280
+ if (tokenResult.rows.length === 0) {
281
+ return null;
282
+ }
283
+ const userId = tokenResult.rows[0].tokenable_id;
284
+ const userResult = await db.sql`
285
+ SELECT * FROM {${usersTable}}
286
+ WHERE id = ${userId}
287
+ `;
288
+ if (userResult.rows.length === 0) {
289
+ return null;
290
+ }
291
+ return userResult.rows[0];
292
+ };
272
293
 
273
294
  const createUsersTable = async (options) => {
274
295
  const connectorName = options.connector.name;
@@ -507,4 +528,4 @@ const runMigrations = async (options) => {
507
528
  console.log("[Nuxt Users] All migrations successfull \u2705");
508
529
  };
509
530
 
510
- export { createUser as a, updateUserPassword as b, checkTableExists as c, createUsersTable as d, createPersonalAccessTokensTable as e, findUserByEmail as f, createPasswordResetTokensTable as g, createMigrationsTable as h, getPasswordValidationOptions as i, getPasswordStrengthColor as j, getPasswordStrengthText as k, runMigrations as r, useDb as u, validatePassword as v };
531
+ export { createUser as a, updateUserPassword as b, checkTableExists as c, createUsersTable as d, createPersonalAccessTokensTable as e, findUserByEmail as f, getCurrentUserFromToken as g, createPasswordResetTokensTable as h, createMigrationsTable as i, getPasswordValidationOptions as j, getPasswordStrengthColor as k, getPasswordStrengthText as l, runMigrations as r, useDb as u, validatePassword as v };
package/dist/utils.d.mts CHANGED
@@ -24,6 +24,10 @@ declare const findUserByEmail: (email: string, options: ModuleOptions) => Promis
24
24
  * Hashes the new password before storing.
25
25
  */
26
26
  declare const updateUserPassword: (email: string, newPassword: string, options: ModuleOptions) => Promise<void>;
27
+ /**
28
+ * Gets the current user from an authentication token.
29
+ */
30
+ declare const getCurrentUserFromToken: (token: string, options: ModuleOptions) => Promise<User | null>;
27
31
 
28
32
  declare const createUsersTable: (options: ModuleOptions) => Promise<void>;
29
33
 
@@ -60,5 +64,5 @@ declare const validatePassword: (password: string, options?: PasswordValidationO
60
64
  declare const getPasswordStrengthColor: (strength: "weak" | "medium" | "strong") => string;
61
65
  declare const getPasswordStrengthText: (strength: "weak" | "medium" | "strong") => string;
62
66
 
63
- export { checkTableExists, createMigrationsTable, createPasswordResetTokensTable, createPersonalAccessTokensTable, createUser, createUsersTable, findUserByEmail, getPasswordStrengthColor, getPasswordStrengthText, getPasswordValidationOptions, runMigrations, updateUserPassword, useDb, validatePassword };
67
+ export { checkTableExists, createMigrationsTable, createPasswordResetTokensTable, createPersonalAccessTokensTable, createUser, createUsersTable, findUserByEmail, getCurrentUserFromToken, getPasswordStrengthColor, getPasswordStrengthText, getPasswordValidationOptions, runMigrations, updateUserPassword, useDb, validatePassword };
64
68
  export type { PasswordValidationOptions, PasswordValidationResult };
package/dist/utils.d.ts CHANGED
@@ -24,6 +24,10 @@ declare const findUserByEmail: (email: string, options: ModuleOptions) => Promis
24
24
  * Hashes the new password before storing.
25
25
  */
26
26
  declare const updateUserPassword: (email: string, newPassword: string, options: ModuleOptions) => Promise<void>;
27
+ /**
28
+ * Gets the current user from an authentication token.
29
+ */
30
+ declare const getCurrentUserFromToken: (token: string, options: ModuleOptions) => Promise<User | null>;
27
31
 
28
32
  declare const createUsersTable: (options: ModuleOptions) => Promise<void>;
29
33
 
@@ -60,5 +64,5 @@ declare const validatePassword: (password: string, options?: PasswordValidationO
60
64
  declare const getPasswordStrengthColor: (strength: "weak" | "medium" | "strong") => string;
61
65
  declare const getPasswordStrengthText: (strength: "weak" | "medium" | "strong") => string;
62
66
 
63
- export { checkTableExists, createMigrationsTable, createPasswordResetTokensTable, createPersonalAccessTokensTable, createUser, createUsersTable, findUserByEmail, getPasswordStrengthColor, getPasswordStrengthText, getPasswordValidationOptions, runMigrations, updateUserPassword, useDb, validatePassword };
67
+ export { checkTableExists, createMigrationsTable, createPasswordResetTokensTable, createPersonalAccessTokensTable, createUser, createUsersTable, findUserByEmail, getCurrentUserFromToken, getPasswordStrengthColor, getPasswordStrengthText, getPasswordValidationOptions, runMigrations, updateUserPassword, useDb, validatePassword };
64
68
  export type { PasswordValidationOptions, PasswordValidationResult };
package/dist/utils.mjs CHANGED
@@ -1,3 +1,3 @@
1
- export { c as checkTableExists, h as createMigrationsTable, g as createPasswordResetTokensTable, e as createPersonalAccessTokensTable, a as createUser, d as createUsersTable, f as findUserByEmail, j as getPasswordStrengthColor, k as getPasswordStrengthText, i as getPasswordValidationOptions, r as runMigrations, b as updateUserPassword, u as useDb, v as validatePassword } from './shared/nuxt-users.37k1R3_g.mjs';
1
+ export { c as checkTableExists, i as createMigrationsTable, h as createPasswordResetTokensTable, e as createPersonalAccessTokensTable, a as createUser, d as createUsersTable, f as findUserByEmail, g as getCurrentUserFromToken, k as getPasswordStrengthColor, l as getPasswordStrengthText, j as getPasswordValidationOptions, r as runMigrations, b as updateUserPassword, u as useDb, v as validatePassword } from './shared/nuxt-users.C_UkhLJ9.mjs';
2
2
  import 'bcrypt';
3
3
  import 'db0';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-users",
3
- "version": "1.6.0",
3
+ "version": "1.6.1",
4
4
  "description": "A comprehensive user management module for Nuxt 3 applications with authentication, database support, and CLI tools",
5
5
  "keywords": [
6
6
  "nuxt",