Snow
Snow
Explore posts from servers
TTCTheo's Typesafe Cult
Created by Snow on 10/9/2023 in #questions
Using CloudFormation with NextJS
I've been recently looking into using AWS CDK / Cloud Formation (still a bit confused?). However to create a Stack it seems you need to use CDK to synthesise a CF Template which you can then cdk deploy. So my question(s) is: How can I use CDK / CF Templates with NextJS, should I use the cdk init to create a new ts-app, synthesize and place the template in my NextJS project? SHOULD I even use CF, I'm trying to make easy setup for my App which uses several AWS Services (S3, CloudFront, SNS/SES, etc...) so that I can get kind of an overview to collaborators which services I use, along with easy to set up on other AWS accounts if ever needed. I tried to look up information on this, but NextJS is kind of special in the sense it doesn't really have an entry point? And specific information on this topic seems to be non existant or really hard to come by, so if anyone has any experience with this who could help out, it would be much appreciated!
1 replies
TTCTheo's Typesafe Cult
Created by Snow on 10/7/2023 in #questions
NextAuth /verify-request double-triggering, invalidating token
Hello, I'm experiencing some issues with the EmailProvider from NextAuth. Unable to find any answers online I thought I'd take my question here, if someone has had any similar issues. So for some context, I am running MongoDB /w Prisma and this is is model for the VerificationToken (however I doubt the issue lies here)
model VerificationToken {
id String @id @default(auto()) @map("_id") @db.ObjectId
identifier String
token String @unique
expires DateTime

@@unique([identifier, token])
}
model VerificationToken {
id String @id @default(auto()) @map("_id") @db.ObjectId
identifier String
token String @unique
expires DateTime

@@unique([identifier, token])
}
my auth.ts like so:
export const authOptions: NextAuthOptions = {
callbacks: {
signIn: async (user) => {
const { name, image, id } = user.user;
if (!name || !image)
await prisma.user.update({
where: { id },
data: {
name: !name ? "User" : undefined,
image: !image
? "/assets/imgs/default-avatar.png"
: undefined,
},
});

return true;
},
session: ({ session, user }) => ({
...session,
user: {
...session.user,
id: user.id,
tag: user.tag,
lastTagReset: user.lastTagReset,
role: user.role,
},
}),
},
adapter: PrismaAdapter(prisma),
providers: [
...
EmailProvider({
server: env.EMAIL_SERVER,
from: env.EMAIL_FROM,
}),
...
],
cookies: {
pkceCodeVerifier: {
name: "next-auth.pkce.code_verifier",
options: {
httpOnly: true,
sameSite: "none",
path: "/",
secure: true,
},
},
},
};
export const authOptions: NextAuthOptions = {
callbacks: {
signIn: async (user) => {
const { name, image, id } = user.user;
if (!name || !image)
await prisma.user.update({
where: { id },
data: {
name: !name ? "User" : undefined,
image: !image
? "/assets/imgs/default-avatar.png"
: undefined,
},
});

return true;
},
session: ({ session, user }) => ({
...session,
user: {
...session.user,
id: user.id,
tag: user.tag,
lastTagReset: user.lastTagReset,
role: user.role,
},
}),
},
adapter: PrismaAdapter(prisma),
providers: [
...
EmailProvider({
server: env.EMAIL_SERVER,
from: env.EMAIL_FROM,
}),
...
],
cookies: {
pkceCodeVerifier: {
name: "next-auth.pkce.code_verifier",
options: {
httpOnly: true,
sameSite: "none",
path: "/",
secure: true,
},
},
},
};
I have placed a quick console.log in the NextAuth src, just to possibly get some more information, to which I discovered that it seems to double trigger
useVerificationToken {
identifier: '...',
token: 'b8df22aa3d0ff9f1321805437ea807d6199d833e3ec4b0cba278d79ee0404793'
}
useVerificationToken {
identifier: '...',
token: 'b8df22aa3d0ff9f1321805437ea807d6199d833e3ec4b0cba278d79ee0404793'
}
useVerificationToken {
identifier: '...',
token: 'b8df22aa3d0ff9f1321805437ea807d6199d833e3ec4b0cba278d79ee0404793'
}
useVerificationToken {
identifier: '...',
token: 'b8df22aa3d0ff9f1321805437ea807d6199d833e3ec4b0cba278d79ee0404793'
}
I am also able to see the actual session in the DB, which then gets REMOVED but still gives errors that it was "unable to find the record"
prisma:error
Invalid `prisma.verificationToken.delete()` invocation:


An operation failed because it depends on one or more records that were required but not found. Record to delete does not exist.
{"name":"PrismaClientKnownRequestError","code":"P2025","clientVersion":"5.3.1","meta":{"cause":"Record to delete does not exist."}}
prisma:error
Invalid `prisma.verificationToken.delete()` invocation:


An operation failed because it depends on one or more records that were required but not found. Record to delete does not exist.
{"name":"PrismaClientKnownRequestError","code":"P2025","clientVersion":"5.3.1","meta":{"cause":"Record to delete does not exist."}}
ANY help is appreciated, I've been banging my head over this for hours now and I don't understand why it's acting like this
4 replies