#continued

1 messages · Page 1 of 1 (latest)

split sparrow
#

what is the value of session when you access the dashboard? @peak sinew

peak sinew
#

when logged in, the value issession: {user: {…}, expires: '2022-07-29T12:09:36.787Z'} when logged out the value is null

#

but even after loggin out, when i manually type the url in the browser, i can still access dashboard, with a session null

split sparrow
peak sinew
#

this is my [...nextauth] ```export default NextAuth({
session: {
jwt: true,
},
providers: [
CredentialsProvider({
name: "Credentials",
async authorize(credentials) {
const user = await prisma.user.findUnique({
where: { user_email: credentials.email },
});

    if (!user) {
      await prisma.$disconnect();
      throw new Error("User not found");
    }

    const ValidPassWord = await verifyPassword(
        credentials.user_password,
        user.user_password
    );


    if (!ValidPassWord) {
      await prisma.$disconnect();
      throw new Error("PassWord submitted is incorrect");
    }

    await prisma.$disconnect();
    return { email: user.user_email, user_name: user.user_name };
  },
}),

],
});

split sparrow
peak sinew
#

how ?

split sparrow
#
export default NextAuth({
  session: {
    jwt: true,
  },
  providers: [
    CredentialsProvider({
      name: "Credentials",
      async authorize(credentials) {
        const user = await prisma.user.findUnique({
          where: { user_email: credentials.email },
        });

        if (!user) {
          await prisma.$disconnect();
          throw new Error("User not found");
        }

        const ValidPassWord = await verifyPassword(
            credentials.user_password,
            user.user_password
        );
        if (!ValidPassWord) {
          await prisma.$disconnect();
          throw new Error("PassWord submitted is incorrect");
        }

        await prisma.$disconnect();
        return { email: user.user_email, user_name: user.user_name };
      },
    },
  pages: {
    signIn: 'your-url'
  }),
  ],
});
#

@peak sinew

#

in this case it should be '/auth'

peak sinew
#

well, i have added it

#

but same behavior still

#

it looks like getserverside props, is not doing anything

#

even when i comment it out, usesession will work fine

split sparrow
peak sinew
#

the dash board ?

split sparrow
#

yea

peak sinew
#
import { useRouter } from "next/router";
import { useSession, getSession } from "next-auth/react";

import classes from "./DashBord.module.css";
import Pellete from "../../components/UI/Interfaces/Pellete";
import Link from "next/link";

const DashBoard = () => {
  const { data: session } = useSession()
  console.log('session: ', session)

  return (
    <div className={classes.bg}>
      // some jsx
    </div>
  );
};

export default DashBoard;

export async function getServerSideProps(context) {
  const session = await getSession({ req: context.req });
  if (!session) {
    return {
      redirect: {
        destination: "/auth",
        permanent: false,
      },
    };
  }
  return {
    props: {
      session,
    },
  };
}```
split sparrow
#

try printing session there

#

to check if it actually works and to see its value

peak sinew
#

it shows undefined

split sparrow
#

huh, then !session should work

#

try changing it to if (typeof session === undefined)

#

@peak sinew

peak sinew
#

okay

split sparrow
peak sinew
#

wait, even when i have active session, debug shows undefined

#

but chrome client later shows the session

#

ahh

#

im sorry

#

all along, i have been using getserverside props in a none-page component

split sparrow
#

great to hear

peak sinew
#

my bad

split sparrow
#

its ok

peak sinew
#

hello @split sparrow are you still there ?

split sparrow
peak sinew
#

hey

#

what is the NEXT_AUTH URL used for ?

peak sinew
#

nextauth first printed an error demanding i should add a secret (in production) which i did, ```export default NextAuth({
session: {
jwt: true,
},
providers: [
CredentialsProvider({
name: "Credentials",
async authorize(credentials) {
const user = await prisma.user.findUnique({
where: { user_email: credentials.email },
});

    if (!user) {
      await prisma.$disconnect();
      throw new Error("User not found");
    }

    const ValidPassWord = await verifyPassword(
        credentials.user_password,
        user.user_password
    );


    if (!ValidPassWord) {
      await prisma.$disconnect();
      throw new Error("PassWord submitted is incorrect");
    }

    await prisma.$disconnect();
    return { email: user.user_email, user_name: user.user_name };
  },
  pages: {
    signIn: '/auth'
  },
}),

],

secret: process.env.NEXTAUTH_SECRET,
jwt: {
secret: process.env.NEXTAUTH_SECRET,
encryption: true
}

});``` but now it is giving me a different error, i have no idea to troubleshoot

2022-06-30T14:52:27.461Z 6365b6fe-b517-4b89-a5ad-73c4fb670a8c ERROR [next-auth][error][CALLBACK_CREDENTIALS_JWT_ERROR]
https://next-auth.js.org/errors#callback_credentials_jwt_error Signin in with credentials only supported if JWT strategy is enabled UnsupportedStrategy [UnsupportedStrategyError]: Signin in with credentials only supported if JWT strategy is enabled
at assertConfig (/var/task/node_modules/next-auth/core/lib/assert.js:45:14)
at NextAuthHandler (/var/task/node_modules/next-auth/core/index.js:34:52)
at NextAuthNextHandler (/var/task/node_modules/next-auth/next/index.js:16:51

This is a list of errors output from NextAuth.js.

peak sinew
#

now, i was getting client-fetch error, both local and vercel, when i added NEXTAUTH_URL, local is working fine, but then vercel prints [CALLBACK_CREDENTIALS_JWT_ERROR] in its console, but prints client fetch error in chrome console

split sparrow
split sparrow
split sparrow
peak sinew
#

hello, hope youre still here

#

good morning

peak sinew
#

ahh

#

this next-auth thing

#

can fail to work with no reason

#

just had to delete the script and re-write it, for it to work