-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Siddharth
committed
Oct 27, 2023
1 parent
a481814
commit 409e66a
Showing
13 changed files
with
205 additions
and
230 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,57 +1,53 @@ | ||
import { authOptions } from "@/app/api/auth/[...nextauth]/route"; | ||
import VerfiyEmailForm from "./verify-form"; | ||
import { getServerSession } from "next-auth"; | ||
import { redirect } from "next/navigation"; | ||
import { getServerSession } from "next-auth" | ||
import { redirect } from "next/navigation" | ||
|
||
import VerifyEmailForm from "./verify-form" | ||
|
||
import { | ||
deleteEmail, | ||
emailRegistrationInitiate, | ||
} from "@/services/graphql/mutations/email"; | ||
import { useFormStatus } from "react-dom"; | ||
} from "@/services/graphql/mutations/email" | ||
import { authOptions } from "@/app/api/auth/[...nextauth]/route" | ||
|
||
type VerifyEmailProp = { | ||
emailRegistrationId: string | null | undefined; | ||
}; | ||
emailRegistrationId: string | null | undefined | ||
} | ||
|
||
export default async function VerifyEmail({ | ||
searchParams, | ||
}: { | ||
searchParams: VerifyEmailProp; | ||
searchParams: VerifyEmailProp | ||
}) { | ||
let { emailRegistrationId } = searchParams; | ||
const session = await getServerSession(authOptions); | ||
const token = session?.accessToken; | ||
let { emailRegistrationId } = searchParams | ||
const session = await getServerSession(authOptions) | ||
const token = session?.accessToken | ||
|
||
// this is if user has address but not verified | ||
if (!emailRegistrationId || typeof emailRegistrationId !== "string") { | ||
const email = session?.userData.data.me?.email?.address; | ||
const email = session?.userData.data.me?.email?.address | ||
if (!email || typeof email !== "string" || !token) { | ||
redirect("/security"); | ||
redirect("/security") | ||
} | ||
|
||
await deleteEmail(token); | ||
let data; | ||
await deleteEmail(token) | ||
let data | ||
try { | ||
data = await emailRegistrationInitiate(email, token); | ||
data = await emailRegistrationInitiate(email, token) | ||
} catch (err) { | ||
console.log("error in emailRegistrationInitiate ", err); | ||
redirect("/security"); | ||
console.log("error in emailRegistrationInitiate ", err) | ||
redirect("/security") | ||
} | ||
|
||
if (data?.userEmailRegistrationInitiate.errors.length) { | ||
redirect("/security"); | ||
redirect("/security") | ||
} | ||
|
||
emailRegistrationId = | ||
data?.userEmailRegistrationInitiate.emailRegistrationId; | ||
emailRegistrationId = data?.userEmailRegistrationInitiate.emailRegistrationId | ||
} | ||
|
||
if (!emailRegistrationId && typeof emailRegistrationId !== "string") { | ||
redirect("/security"); | ||
redirect("/security") | ||
} | ||
|
||
return ( | ||
<VerfiyEmailForm | ||
emailRegistrationId={emailRegistrationId} | ||
></VerfiyEmailForm> | ||
); | ||
return <VerifyEmailForm emailRegistrationId={emailRegistrationId}></VerifyEmailForm> | ||
} |
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
Oops, something went wrong.