Endeau.pro
Endeau.pro
NNuxt
Created by Endeau.pro on 2/23/2025 in #❓・help
loggedIn.value always false
@kapa.ai Ok I understand, so can you provide me the code to use my access_token ?
33 replies
NNuxt
Created by Endeau.pro on 2/23/2025 in #❓・help
loggedIn.value always false
@HttpCode(HttpStatus.OK) @Post('login') @Public() signIn(@Body() authDto: AuthDto): Observable<{ access_token: string }> { return this.authService.signIn(authDto.email, authDto.password).pipe( switchMap((token: { access_token: string }) => { return of(token); }), ); }
33 replies
NNuxt
Created by Endeau.pro on 2/23/2025 in #❓・help
loggedIn.value always false
@kapa.ai I have the log : "Logged in: false" and my api in a nestjs api. The code is : "@HttpCode(HttpStatus.OK) @Post('login') @Public() signIn(@Body() authDto: AuthDto): Observable<{ access_token: string }> { return this.authService.signIn(authDto.email, authDto.password).pipe( switchMap((token: { access_token: string }) => { return of(token); }), ); }"
33 replies
NNuxt
Created by Endeau.pro on 2/23/2025 in #❓・help
loggedIn.value always false
@kapa.ai There is my login view page : "<script setup lang="ts"> definePageMeta({ middleware: ['not-authenticated'], }); const { loggedIn, user, fetch: refreshSession } = useUserSession() const credentials = reactive({ email: '', password: '', }) async function login() { $fetch('/api/login', { method: 'POST', body: credentials }) .then(async () => { // Refresh the session on client-side and redirect to the home page await refreshSession() await navigateTo('/dashboard') }) .catch((error) => alert(error)) } </script> <template>"
33 replies
NNuxt
Created by Endeau.pro on 2/23/2025 in #❓・help
loggedIn.value always false
@kapa.ai I have set-cookie with nuxt-session=...
33 replies
NNuxt
Created by Endeau.pro on 2/23/2025 in #❓・help
loggedIn.value always false
@kapa.ai This is my login.post.ts : "import { z } from 'zod' import { defineEventHandler, readBody, createError } from 'h3' const bodySchema = z.object({ email: z.string().email(), password: z.string().min(1) }) export default defineEventHandler(async (event) => { const body = await readBody(event) const result = bodySchema.safeParse(body) if (!result.success) { throw createError({ statusCode: 400, message: 'Invalid request body' }) } const { email, password } = result.data try { console.log("requesting login") const response = await fetch('http://laura-s-website-backend:3000/api/auth/login', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ email, password }) }) console.log("response", response) if (!response.ok) { throw new Error('Failed to authenticate') } const data = await response.json() // Assuming the response contains user data console.log("data", data) await setUserSession(event, { user: { name: 'John Doe' } }) console.log("login successful") return {}; } catch (error) { console.log("Erreur " + error) throw createError({ statusCode: 401, message: 'Invalid credentials' }) } }) "
33 replies