11import { getCurrentUserFromToken } from '../server/utils/user'
2-
3- import { useRuntimeConfig } from '#imports'
42import { getCookie , type H3Event } from 'h3'
53import type { ModuleOptions , UserWithoutPassword } from '../../types'
64
@@ -22,23 +20,24 @@ import type { ModuleOptions, UserWithoutPassword } from '../../types'
2220 * })
2321 * ```
2422 */
25- const getCurrentUser = async ( event : H3Event ) : Promise < UserWithoutPassword | null > => {
26- // Get the auth token from cookies
27- const token = getCookie ( event , 'auth_token' )
23+ export const useServerAuth = ( ) => {
24+ const getCurrentUser = async ( event : H3Event ) : Promise < UserWithoutPassword | null > => {
25+ const { useRuntimeConfig } = await import ( '#imports' )
26+ // Get the auth token from cookies
27+ const token = getCookie ( event , 'auth_token' )
2828
29- if ( ! token ) {
30- return null
31- }
29+ if ( ! token ) {
30+ return null
31+ }
3232
33- // Get the module options from runtime config
34- const { nuxtUsers } = useRuntimeConfig ( )
33+ // Get the module options from runtime config
34+ const { nuxtUsers } = useRuntimeConfig ( )
3535
36- // Get the current user using the token
37- const user = await getCurrentUserFromToken ( token , nuxtUsers as ModuleOptions , false )
38- return user
39- }
36+ // Get the current user using the token
37+ const user = await getCurrentUserFromToken ( token , nuxtUsers as ModuleOptions , false )
38+ return user
39+ }
4040
41- export const useServerAuth = ( ) => {
4241 return {
4342 getCurrentUser
4443 }
0 commit comments