Derock
Derock
Explore posts from servers
TTCTheo's Typesafe Cult
Created by Derock on 4/16/2023 in #questions
NextAuth "[next-auth][error][JWT_SESSION_ERROR]" (CredentialsProvider)
error message could definitely use some work tho
10 replies
TTCTheo's Typesafe Cult
Created by Derock on 4/16/2023 in #questions
NextAuth "[next-auth][error][JWT_SESSION_ERROR]" (CredentialsProvider)
forgot to create a jwt callback
callbacks: {
jwt: ({ token, user }) => ({
...token,
user,
}),
},
callbacks: {
jwt: ({ token, user }) => ({
...token,
user,
}),
},
10 replies
TTCTheo's Typesafe Cult
Created by Derock on 4/16/2023 in #questions
NextAuth "[next-auth][error][JWT_SESSION_ERROR]" (CredentialsProvider)
nvm
10 replies
TTCTheo's Typesafe Cult
Created by Derock on 4/16/2023 in #questions
NextAuth "[next-auth][error][JWT_SESSION_ERROR]" (CredentialsProvider)
full error:
[next-auth][error][JWT_SESSION_ERROR]
https://next-auth.js.org/errors#jwt_session_error Cannot read properties of undefined (reading 'id') {
message: "Cannot read properties of undefined (reading 'id')",
stack: "TypeError: Cannot read properties of undefined (reading 'id')\n" +
' at Object.session (webpack-internal:///(api)/./src/server/auth.ts:32:30)\n' +
' at Object.session (/home/derock/beelikecoders-hackathon-2023/node_modules/.pnpm/[email protected]_yucv4tfv7v7nrkw2uguegj6e7e/node_modules/next-auth/core/routes/session.js:55:46)\n' +
' at async AuthHandler (/home/derock/beelikecoders-hackathon-2023/node_modules/.pnpm/[email protected]_yucv4tfv7v7nrkw2uguegj6e7e/node_modules/next-auth/core/index.js:158:27)\n' +
' at async NextAuthApiHandler (/home/derock/beelikecoders-hackathon-2023/node_modules/.pnpm/[email protected]_yucv4tfv7v7nrkw2uguegj6e7e/node_modules/next-auth/next/index.js:24:19)\n' +
' at async NextAuth._args$ (/home/derock/beelikecoders-hackathon-2023/node_modules/.pnpm/[email protected]_yucv4tfv7v7nrkw2uguegj6e7e/node_modules/next-auth/next/index.js:110:14)',
name: 'TypeError'
}
[next-auth][error][JWT_SESSION_ERROR]
https://next-auth.js.org/errors#jwt_session_error Cannot read properties of undefined (reading 'id') {
message: "Cannot read properties of undefined (reading 'id')",
stack: "TypeError: Cannot read properties of undefined (reading 'id')\n" +
' at Object.session (webpack-internal:///(api)/./src/server/auth.ts:32:30)\n' +
' at Object.session (/home/derock/beelikecoders-hackathon-2023/node_modules/.pnpm/[email protected]_yucv4tfv7v7nrkw2uguegj6e7e/node_modules/next-auth/core/routes/session.js:55:46)\n' +
' at async AuthHandler (/home/derock/beelikecoders-hackathon-2023/node_modules/.pnpm/[email protected]_yucv4tfv7v7nrkw2uguegj6e7e/node_modules/next-auth/core/index.js:158:27)\n' +
' at async NextAuthApiHandler (/home/derock/beelikecoders-hackathon-2023/node_modules/.pnpm/[email protected]_yucv4tfv7v7nrkw2uguegj6e7e/node_modules/next-auth/next/index.js:24:19)\n' +
' at async NextAuth._args$ (/home/derock/beelikecoders-hackathon-2023/node_modules/.pnpm/[email protected]_yucv4tfv7v7nrkw2uguegj6e7e/node_modules/next-auth/next/index.js:110:14)',
name: 'TypeError'
}
10 replies
TTCTheo's Typesafe Cult
Created by Derock on 4/16/2023 in #questions
NextAuth "[next-auth][error][JWT_SESSION_ERROR]" (CredentialsProvider)
const SignUp: NextPage<
InferGetServerSidePropsType<typeof getServerSideProps>
> = (props) => {
// ...
const [error, setError] = useState<string | null>(null);
const form = useForm(...);
const router = useRouter();
// ...

return (
// ...
<form
onSubmit={form.onSubmit((data) => {
signIn("credentials", {
username: data.username,
password: data.password,
redirect: false,
}).then((res) => {
console.log(res);
if (!res?.ok) {
let error = res?.error;

if (error === "CredentialsSignin") error = "Invalid credentials";

setError(error ?? "Invalid credentials");
} else {
router.push("/");
}
});
})}
className="flex w-80 flex-col gap-2"
> {/* ... */} </form>
// ...
)
}

export default SignUp;

export const getServerSideProps = async (
context: GetServerSidePropsContext
) => {
const session = await getServerAuthSession(context);

if (session) {
return {
redirect: {
destination: "/",
permanent: false,
},

props: {},
};
}

return {
props: {},
};
};
const SignUp: NextPage<
InferGetServerSidePropsType<typeof getServerSideProps>
> = (props) => {
// ...
const [error, setError] = useState<string | null>(null);
const form = useForm(...);
const router = useRouter();
// ...

return (
// ...
<form
onSubmit={form.onSubmit((data) => {
signIn("credentials", {
username: data.username,
password: data.password,
redirect: false,
}).then((res) => {
console.log(res);
if (!res?.ok) {
let error = res?.error;

if (error === "CredentialsSignin") error = "Invalid credentials";

setError(error ?? "Invalid credentials");
} else {
router.push("/");
}
});
})}
className="flex w-80 flex-col gap-2"
> {/* ... */} </form>
// ...
)
}

export default SignUp;

export const getServerSideProps = async (
context: GetServerSidePropsContext
) => {
const session = await getServerAuthSession(context);

if (session) {
return {
redirect: {
destination: "/",
permanent: false,
},

props: {},
};
}

return {
props: {},
};
};
10 replies
TTCTheo's Typesafe Cult
Created by Derock on 4/16/2023 in #questions
NextAuth "[next-auth][error][JWT_SESSION_ERROR]" (CredentialsProvider)
here is my signin page
10 replies
TTCTheo's Typesafe Cult
Created by Derock on 4/16/2023 in #questions
NextAuth "[next-auth][error][JWT_SESSION_ERROR]" (CredentialsProvider)
The error occurs when i try to sign in
10 replies