UNPKG

nuxt-users

Version:

A comprehensive user management module for Nuxt 3 and Nuxt 4 applications with authentication, authorization, database support, and CLI tools

23 lines (22 loc) 717 B
import { createError, defineEventHandler, getCookie } from "h3"; import { useRuntimeConfig } from "#imports"; import { getCurrentUserFromToken } from "../../utils/index.js"; export default defineEventHandler(async (event) => { const { nuxtUsers } = useRuntimeConfig(); const options = nuxtUsers; const token = getCookie(event, "auth_token"); if (!token) { throw createError({ statusCode: 401, statusMessage: "Unauthorized - No authentication token found" }); } const user = await getCurrentUserFromToken(token, options); if (!user) { throw createError({ statusCode: 401, statusMessage: "Unauthorized - Invalid authentication token" }); } return { user }; });