nuxt-users 1.14.0 → 1.15.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 +42 -0
- package/dist/cli.mjs +1 -1
- package/dist/module.json +1 -1
- package/dist/runtime/composables/useServerAuth.d.ts +23 -0
- package/dist/runtime/composables/useServerAuth.js +17 -0
- package/dist/runtime/server/utils/index.d.ts +1 -1
- package/dist/runtime/server/utils/index.js +1 -1
- package/dist/runtime/server/utils/user.d.ts +0 -21
- package/dist/runtime/server/utils/user.js +0 -11
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,48 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
3
|
|
|
4
|
+
## v1.15.1
|
|
5
|
+
|
|
6
|
+
[compare changes](https://github.com/rrd108/nuxt-users/compare/v1.15.0...v1.15.1)
|
|
7
|
+
|
|
8
|
+
### 🩹 Fixes
|
|
9
|
+
|
|
10
|
+
- Import path ([1d1013e](https://github.com/rrd108/nuxt-users/commit/1d1013e))
|
|
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
|
+
- Fix whitespace ([517d60d](https://github.com/rrd108/nuxt-users/commit/517d60d))
|
|
19
|
+
- **release:** V1.15.0 ([2cc5d6a](https://github.com/rrd108/nuxt-users/commit/2cc5d6a))
|
|
20
|
+
|
|
21
|
+
### ❤️ Contributors
|
|
22
|
+
|
|
23
|
+
- Rrd108 ([@rrd108](https://github.com/rrd108))
|
|
24
|
+
|
|
25
|
+
## v1.15.0
|
|
26
|
+
|
|
27
|
+
[compare changes](https://github.com/rrd108/nuxt-users/compare/v1.14.0...v1.15.0)
|
|
28
|
+
|
|
29
|
+
### 🚀 Enhancements
|
|
30
|
+
|
|
31
|
+
- Add getCurrentUser utility ([0096fb2](https://github.com/rrd108/nuxt-users/commit/0096fb2))
|
|
32
|
+
|
|
33
|
+
### 💅 Refactors
|
|
34
|
+
|
|
35
|
+
- GetCurrentUser from a utility to a composable ([10149d2](https://github.com/rrd108/nuxt-users/commit/10149d2))
|
|
36
|
+
|
|
37
|
+
### 🏡 Chore
|
|
38
|
+
|
|
39
|
+
- **release:** V1.14.0 ([6c32154](https://github.com/rrd108/nuxt-users/commit/6c32154))
|
|
40
|
+
- Fix whitespace ([517d60d](https://github.com/rrd108/nuxt-users/commit/517d60d))
|
|
41
|
+
|
|
42
|
+
### ❤️ Contributors
|
|
43
|
+
|
|
44
|
+
- Rrd108 ([@rrd108](https://github.com/rrd108))
|
|
45
|
+
|
|
4
46
|
## v1.14.0
|
|
5
47
|
|
|
6
48
|
[compare changes](https://github.com/rrd108/nuxt-users/compare/v1.13.0...v1.14.0)
|
package/dist/cli.mjs
CHANGED
package/dist/module.json
CHANGED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type H3Event } from 'h3';
|
|
2
|
+
import type { UserWithoutPassword } from '../../types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Server-side composable for authentication utilities
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* // server/api/protected-route.get.ts
|
|
9
|
+
* export default defineEventHandler(async (event) => {
|
|
10
|
+
* const { getCurrentUser } = useServerAuth()
|
|
11
|
+
* const user = await getCurrentUser(event)
|
|
12
|
+
*
|
|
13
|
+
* if (!user) {
|
|
14
|
+
* throw createError({ statusCode: 401, statusMessage: 'Unauthorized' })
|
|
15
|
+
* }
|
|
16
|
+
*
|
|
17
|
+
* return { message: `Hello ${user.name}!` }
|
|
18
|
+
* })
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare const useServerAuth: () => {
|
|
22
|
+
getCurrentUser: (event: H3Event) => Promise<UserWithoutPassword | null>;
|
|
23
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { getCurrentUserFromToken } from "../server/utils/user.js";
|
|
2
|
+
import { getCookie } from "h3";
|
|
3
|
+
export const useServerAuth = () => {
|
|
4
|
+
const getCurrentUser = async (event) => {
|
|
5
|
+
const { useRuntimeConfig } = await import("#imports");
|
|
6
|
+
const token = getCookie(event, "auth_token");
|
|
7
|
+
if (!token) {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
const { nuxtUsers } = useRuntimeConfig();
|
|
11
|
+
const user = await getCurrentUserFromToken(token, nuxtUsers, false);
|
|
12
|
+
return user;
|
|
13
|
+
};
|
|
14
|
+
return {
|
|
15
|
+
getCurrentUser
|
|
16
|
+
};
|
|
17
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { useDb, checkTableExists } from './db.js';
|
|
2
|
-
export { createUser, findUserByEmail, updateUserPassword, getCurrentUserFromToken,
|
|
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,
|
|
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