iPheNoMeNaL-oG
iPheNoMeNaL-oG
Explore posts from servers
BABetter Auth
Created by iPheNoMeNaL-oG on 1/27/2025 in #help
Resend Verification Email
I'm trying to resend the email verification when a user tries to sign-in and has not yet verified their email..
async function onSubmit(values: z.infer<typeof signInFormSchema>) {
const { email, password } = values;
await authClient.signIn.email(
{ email, password, callbackURL: "/dashboard"} ,
{
onRequest: () => {},
onSuccess: () => {},
onError: async (ctx) => {
if (ctx.error.status === 403) {
setError("Check inbox, verify email");
console.log("sending email to ...", email);
// resend the verification email
try {
await authClient.sendVerificationEmail({
email,
callbackURL: "/dashboard",
});
toast({title: "Verification email sent"});
async function onSubmit(values: z.infer<typeof signInFormSchema>) {
const { email, password } = values;
await authClient.signIn.email(
{ email, password, callbackURL: "/dashboard"} ,
{
onRequest: () => {},
onSuccess: () => {},
onError: async (ctx) => {
if (ctx.error.status === 403) {
setError("Check inbox, verify email");
console.log("sending email to ...", email);
// resend the verification email
try {
await authClient.sendVerificationEmail({
email,
callbackURL: "/dashboard",
});
toast({title: "Verification email sent"});
I'm getting the correct error code but the email never gets sent...
POST /api/auth/sign-in/email?currentURL=http%3A%2F%2Flocalhost%3A3001%2Fsign-in 403 in 5016ms
POST /api/auth/send-verification-email?currentURL=http%3A%2F%2Flocalhost%3A3001%2Fsign-in 200 in 275ms
POST /api/auth/sign-in/email?currentURL=http%3A%2F%2Flocalhost%3A3001%2Fsign-in 403 in 5016ms
POST /api/auth/send-verification-email?currentURL=http%3A%2F%2Flocalhost%3A3001%2Fsign-in 200 in 275ms
7 replies
PPrisma
Created by iPheNoMeNaL-oG on 7/15/2024 in #help-and-questions
Using upsert when `Notifications` table doesn't exist yet for user
I have a query to update a users notification preferences, but there's no data existing data yet inside the table. How can I change the query to accodomate that?
await prisma.notifications.upsert({
where: { id },
data: {
type,
communication,
marketing,
social,
security,
mobile,
},
});
await prisma.notifications.upsert({
where: { id },
data: {
type,
communication,
marketing,
social,
security,
mobile,
},
});
I assume upsert is what needs to be used? For reference here is my Notifications model
model Notifications {
id String @id @default(cuid())
userId String
type NotificationType @default(none)
mobile Boolean
communication Boolean
social Boolean
marketing Boolean
security Boolean
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
}
model Notifications {
id String @id @default(cuid())
userId String
type NotificationType @default(none)
mobile Boolean
communication Boolean
social Boolean
marketing Boolean
security Boolean
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
}
3 replies
PPrisma
Created by iPheNoMeNaL-oG on 6/13/2024 in #help-and-questions
Updating user info in db using forms
I have a basic user model
model User {
id String @id @default(cuid())
name String?
email String? @unique
emailVerified DateTime?
image String?
password String
username String @unique
role Role @default(user)
accounts Account[]
sessions Session[]
}
model User {
id String @id @default(cuid())
name String?
email String? @unique
emailVerified DateTime?
image String?
password String
username String @unique
role Role @default(user)
accounts Account[]
sessions Session[]
}
I have a form that allows the user to update email, username, etc. I'm using a simple update method
const updateUser = await prisma.user.update({
where: {
username: username,
},
data: {
username: data.username,
},
});
const updateUser = await prisma.user.update({
where: {
username: username,
},
data: {
username: data.username,
},
});
For those using nextjs, is it best to put this function in a server action or make an api route and call it there?
10 replies