Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "Error: Error serializing .session.user.image" #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion pages/api/auth/[...nextauth].ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ export const authOptions: NextAuthOptions = {
},
async session({ session, token }) {
console.log(`Executing session() with token ${token.expires_at}`)
session.error = token.error
// You need to set the user object properly in jwt callback,
// Error: Error serializing .session.user.image was occuring because
// session.user.image was undefined, it needs to be value || null
session.user = { name: "", email: null, image: null };
return session
},
},
Expand Down
5 changes: 3 additions & 2 deletions pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Layout from "../components/layout"
import { GetServerSideProps } from "next"
import { getSession } from "next-auth/react"
import { getServerSession } from "next-auth"
import { authOptions } from "./api/auth/[...nextauth]"

export default function IndexPage() {
return (
Expand All @@ -16,7 +17,7 @@ export default function IndexPage() {

//Token is not persisting when using server side session
export const getServerSideProps: GetServerSideProps = async (context) => {
const session = await getSession(context)
const session = await getServerSession(context.req, context.res, authOptions)
return {
props: {
session
Expand Down