#continued
1 messages · Page 1 of 1 (latest)
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
have you defined the url of your custom signin page in [...nextauth].js?
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 };
},
}),
],
});
try adding the pages param after the authorize function
how ?
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'
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
try screenshotting the file for me
the dash board ?
yea
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,
},
};
}```
try print debugging getserversideprops
try printing session there
to check if it actually works and to see its value
huh, then !session should work
try changing it to if (typeof session === undefined)
@peak sinew
okay
did it work?
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
😅 so thats why
great to hear
my bad
its ok
hello @split sparrow are you still there ?
sup
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.
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
its used for redirecting the user after signing in
write
session: {
strategy: 'jwt'
}
instead of
session: {
jwt: true
}
also you should change NEXTAUTH_URL to the name of the vercel website youre deploying to
did you mean the domain ?