Building a new website everyday to kickstart any new project I am recruited for.
verify passphrase
5 files changed, +54 -4
+6-0008_hygofitweb/app/actions.ts
| @@ -0,0 +1,6 @@ | ||
| 1 | +"use server"; | |
| 2 | + | |
| 3 | +export async function verifyGuess(guess: string): boolean { | |
| 4 | + console.log("guess", guess); | |
| 5 | + return guess === process.env.MESSAGE_SECRET; | |
| 6 | +} |
+34-2008_hygofitweb/app/page.tsx
| @@ -1,7 +1,39 @@ | ||
| 1 | +"use client"; | |
| 2 | + | |
| 3 | +import { useState } from "react"; | |
| 4 | +import { verifyGuess } from "./actions"; | |
| 5 | + | |
| 1 | 6 | export default function Home() { |
| 7 | + const [isVerified, setIsVerified] = useState(false); | |
| 2 | 8 | return ( |
| 3 | - <div> | |
| 4 | - <div className="h-96">Content</div> | |
| 9 | + <div className="flex w-full justify-center h-full"> | |
| 10 | + {isVerified ? ( | |
| 11 | + <form | |
| 12 | + className="flex flex-col gap-4" | |
| 13 | + action={() => { | |
| 14 | + // Send a message to apn | |
| 15 | + }} | |
| 16 | + > | |
| 17 | + <h1 className="mx-auto">Send a message to the app users</h1> | |
| 18 | + <input className="mx-auto" type="text" name="message" /> | |
| 19 | + <button className="mx-auto" type="submit"> | |
| 20 | + Send | |
| 21 | + </button> | |
| 22 | + </form> | |
| 23 | + ) : ( | |
| 24 | + <form | |
| 25 | + className="flex flex-col gap-4" | |
| 26 | + action={(formData) => { | |
| 27 | + verifyGuess(formData.get("guess") as string) && setIsVerified(true); | |
| 28 | + }} | |
| 29 | + > | |
| 30 | + <h1 className="mx-auto">Guess the secret phrases</h1> | |
| 31 | + <input className="mx-auto" type="password" name="guess" /> | |
| 32 | + <button className="mx-auto" type="submit"> | |
| 33 | + Submit | |
| 34 | + </button> | |
| 35 | + </form> | |
| 36 | + )} | |
| 5 | 37 | </div> |
| 6 | 38 | ); |
| 7 | 39 | } |
+0-1008_hygofitweb/auth.ts
| @@ -1,7 +1,6 @@ | ||
| 1 | 1 | import { prisma } from "@/prisma"; |
| 2 | 2 | import { PrismaAdapter } from "@auth/prisma-adapter"; |
| 3 | 3 | import NextAuth from "next-auth"; |
| 4 | -import Credentials from "next-auth/providers/credentials"; | |
| 5 | 4 | |
| 6 | 5 | export const { handlers, auth, signIn, signOut } = NextAuth({ |
| 7 | 6 | adapter: PrismaAdapter(prisma), |
+7-1008_hygofitweb/middleware.ts
| @@ -1,6 +1,12 @@ | ||
| 1 | +import { prisma } from "./prisma"; | |
| 2 | + | |
| 1 | 3 | const deviceMiddleware = async (req: Request) => { |
| 2 | 4 | const headers = new Headers(req.headers); |
| 3 | - const deviceId = headers.get("Device-ID"); | |
| 5 | + const id = headers.get("Device-ID"); | |
| 6 | + | |
| 7 | + if (id) { | |
| 8 | + prisma.device.upsert({ where: { id }, update: {}, create: { id } }); | |
| 9 | + } | |
| 4 | 10 | }; |
| 5 | 11 | |
| 6 | 12 | export default deviceMiddleware; |
+7-0008_hygofitweb/prisma/migrations/20240910080104_make_device/migration.sql
| @@ -0,0 +1,7 @@ | ||
| 1 | +-- CreateTable | |
| 2 | +CREATE TABLE "Device" ( | |
| 3 | + "id" TEXT NOT NULL | |
| 4 | +); | |
| 5 | + | |
| 6 | +-- CreateIndex | |
| 7 | +CREATE UNIQUE INDEX "Device_id_key" ON "Device"("id"); |