How do i simulate a request from logged in user ? #266
-
Hi, i would like to test a loader that redirect to a given route is user is already authenticated // loader.ts
import { json, redirect, type LoaderFunctionArgs } from '@remix-run/node'
import { getUserId } from '~/utils/auth.server'
export default async ({ request }: LoaderFunctionArgs) => {
const userId = await getUserId(request)
if (userId) return redirect('/')
return json({})
} i tried to create a request with cookie containing current logged user but with no success // loader.test.ts
const session = await getSession()
session.set(authenticator.sessionKey, {
id: 'clrhv23nv000034xku7fajd9c',
createdAt: new Date(),
email: '[email protected]',
updatedAt: new Date(),
} satisfies User)
const request = new Request('http://test/join', {
headers: {
Cookie: await commitSession(session),
},
})
const response = await loader({
request,
context: {},
params: {},
})
|
Beta Was this translation helpful? Give feedback.
Answered by
martialanouman
Jan 27, 2024
Replies: 1 comment
-
Never mind. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
martialanouman
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Never mind.
I forgot that i was mocking
'~/utils/auth.server'
. Everything worked once i removed the mock.