-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from TEDx-SJEC/newform
Successfuly added mail features
- Loading branch information
Showing
14 changed files
with
443 additions
and
11 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
Warnings: | ||
- You are about to drop the column `token` on the `VerificationRequest` table. All the data in the column will be lost. | ||
- Added the required column `otp` to the `VerificationRequest` table without a default value. This is not possible if the table is not empty. | ||
*/ | ||
-- RedefineTables | ||
PRAGMA defer_foreign_keys=ON; | ||
PRAGMA foreign_keys=OFF; | ||
CREATE TABLE "new_VerificationRequest" ( | ||
"id" TEXT NOT NULL PRIMARY KEY, | ||
"identifier" TEXT NOT NULL, | ||
"otp" TEXT NOT NULL, | ||
"expires" DATETIME NOT NULL, | ||
"created_at" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updated_at" DATETIME NOT NULL | ||
); | ||
INSERT INTO "new_VerificationRequest" ("created_at", "expires", "id", "identifier", "updated_at") SELECT "created_at", "expires", "id", "identifier", "updated_at" FROM "VerificationRequest"; | ||
DROP TABLE "VerificationRequest"; | ||
ALTER TABLE "new_VerificationRequest" RENAME TO "VerificationRequest"; | ||
CREATE UNIQUE INDEX "VerificationRequest_identifier_otp_key" ON "VerificationRequest"("identifier", "otp"); | ||
PRAGMA foreign_keys=ON; | ||
PRAGMA defer_foreign_keys=OFF; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { NextRequest, NextResponse } from "next/server"; | ||
import sendEmail from "@/utils/sendMail"; | ||
import otpGenerator from "otp-generator"; | ||
import prisma from "@/server/db"; | ||
|
||
export async function POST(req: NextRequest) { | ||
const body = await req.json(); | ||
const otp = otpGenerator.generate(6, { | ||
upperCaseAlphabets: false, | ||
lowerCaseAlphabets: false, | ||
specialChars: false, | ||
}); | ||
|
||
const expiresIn = 10; // 10 minutes | ||
const expiresAt = new Date(Date.now() + expiresIn * 60 * 1000); | ||
|
||
await prisma.verificationRequest.create({ | ||
data: { | ||
identifier: body.email, | ||
otp, | ||
expires: expiresAt, | ||
}, | ||
}); | ||
|
||
console.log(body); | ||
const mailResponse = await sendEmail({ | ||
email: body.email, | ||
name: body.name, | ||
OTP: otp, | ||
}); | ||
|
||
return NextResponse.json({ | ||
message: "Email sent successfully!", | ||
mailResponse, | ||
}); | ||
} | ||
|
||
export async function GET() { | ||
return NextResponse.json({ message: "Hello from the Send mail!" }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.