nuxt-users 1.15.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
CHANGED
|
@@ -1,6 +1,27 @@
|
|
|
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
|
+
|
|
4
25
|
## v1.15.0
|
|
5
26
|
|
|
6
27
|
[compare changes](https://github.com/rrd108/nuxt-users/compare/v1.14.0...v1.15.0)
|
package/dist/cli.mjs
CHANGED
package/dist/module.json
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
import { type H3Event } from 'h3';
|
|
2
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
|
+
*/
|
|
3
21
|
export declare const useServerAuth: () => {
|
|
4
22
|
getCurrentUser: (event: H3Event) => Promise<UserWithoutPassword | null>;
|
|
5
23
|
};
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { getCurrentUserFromToken } from "../server/utils/user.js";
|
|
2
|
-
import { useRuntimeConfig } from "#imports";
|
|
3
2
|
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
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
14
|
return {
|
|
15
15
|
getCurrentUser
|
|
16
16
|
};
|
package/package.json
CHANGED