createSession is not a function
Answered
Giant panda posted this in #help-forum
Giant pandaOP
I'm currently following the guide from https://nextjs.org/docs/app/building-your-application/authentication and im trying to implement sessions, my
And I imported it in my action file via
Why is this throwing
src/app/lib/session/session.ts contains import 'server-only'
import { SignJWT, jwtVerify } from 'jose'
import { SessionPayload } from '@/app/lib/definitions'
import { cookies } from 'next/headers'
export async function createSession(userId: string, username: string) {
/* logic ... */
}And I imported it in my action file via
"use server"
import { createSession } from '@/app/lib/session/session'
export async function register(state: FormState, formData: FormData) {
/* logic ... */
await createSession(createdUser.id, createdUser.username);
redirect('/profile')
}Why is this throwing
Error: (0 , _app_lib_session_session__WEBPACK_IMPORTED_MODULE_4__.createSession) is not a functionAnswered by Giant panda
Okay, I figured it out, the
session.js file wasnt necessary and was overriding my import :c9 Replies
American Shorthair
Do you have a path alias set up for
@?@American Shorthair Do you have a path alias set up for `@`?
Giant pandaOP
I mean in the same file I imported
'@/app/lib/definitions'; correctly so I hope so?@Giant panda I mean in the same file I imported `'@/app/lib/definitions';` correctly so I hope so?
American Shorthair
How is register being called?
@American Shorthair How is register being called?
Giant pandaOP
'use client'
import { register } from '@/app/actions/auth'
export function SignupForm() {
const [state, action] = useFormState(register, undefined)
return (
<form action={action} className="mt-5">American Shorthair
This appears to be calling server side code on the client?
You likely want a route handler: https://nextjs.org/docs/app/building-your-application/routing/route-handlers
@American Shorthair This appears to be calling server side code on the client?
Giant pandaOP
yes someone told me server actions let you do that
Giant pandaOP
Okay, I figured it out, the
session.js file wasnt necessary and was overriding my import :cAnswer