Skip to content

Commit

Permalink
chore: adding support to verify the email and phone for providers
Browse files Browse the repository at this point in the history
  • Loading branch information
shawakash committed Mar 11, 2024
1 parent 325114f commit e234e85
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
10 changes: 8 additions & 2 deletions apps/web/app/api/auth/[...nextauth]/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,14 @@ export const authOptions: NextAuthOptions = {
/**
* create client for third-party provider
*/
//@ts-ignore
const body = {
//@ts-ignore
username: user.username || "",
firstname: user.name?.split(" ")[0] || "",
lastname: user.name?.split(" ")[1] || "",
email: user.email || "",
password: user.id.toString() || "",
//@ts-ignore
password: `Paybox:${user.username}-${user.id}` || "",
};
const response = await fetch(`${BACKEND_URL}/client/providerAuth`, {
method: "post",
Expand All @@ -165,6 +165,8 @@ export const authOptions: NextAuthOptions = {
token.mobile = response.mobile;
token.address = response.address;
token.valid = response.valid;
token.status = response.status;
token.msg = response.msg;

/**
* Fetch the jwt
Expand All @@ -180,6 +182,8 @@ export const authOptions: NextAuthOptions = {
address: response.address,
mobile: response.mobile,
valid: response.valid,
status: response.status,
msg: response.msg,
};
}
return token;
Expand Down Expand Up @@ -216,6 +220,8 @@ export const authOptions: NextAuthOptions = {
mobile: Number(me.mobile),
name: `${me.firstname} ${me.lastname}`,
valid: me.valid,
status: me.status,
msg: me.msg
},
};
},
Expand Down
2 changes: 1 addition & 1 deletion apps/web/app/signup/components/signup-tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function SignupTab() {
}, [session])

return (
<Tabs defaultValue={SignStatus.Details} value={status} className="w-[500px]">
<Tabs defaultValue={status} value={status} className="w-[500px]">
<TabsList className="grid w-full grid-cols-2 bg-zinc-800">
<TabsTrigger value={SignStatus.Details} disabled={status === SignStatus.Verify}>Signup Details</TabsTrigger>
<TabsTrigger value={SignStatus.Verify} disabled={status === SignStatus.Details}>Validations</TabsTrigger>
Expand Down
7 changes: 4 additions & 3 deletions apps/web/app/signup/components/user-auth-signup-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { ToastAction } from "@radix-ui/react-toast";
import { useRecoilState } from "recoil";
import { clientAtom, loadingAtom } from "@paybox/recoil";
import { RocketIcon } from "@radix-ui/react-icons";
import { toast } from "sonner";

interface ClientSignupFormProps extends React.HTMLAttributes<HTMLDivElement> {}

Expand All @@ -44,7 +45,6 @@ export function ClientSignupForm({
const { data: session, update } = useSession(); // Use the useSession hook to get the session state
const [_, setClient] = useRecoilState(clientAtom);
const router = useRouter();
const { toast } = useToast();

React.useEffect(() => {
// Check if the session is defined and navigate to the protected page
Expand All @@ -69,6 +69,7 @@ export function ClientSignupForm({
}).then((_) => {
setIsLoading(false);
});

}
return (
<div className={cn("grid gap-6", className)} {...props}>
Expand Down Expand Up @@ -252,7 +253,7 @@ export function ClientSignupForm({
disabled={isLoading}
onClick={() => {
setIsLoading(true);
signIn("github", { callbackUrl: "/profile" }).then(() =>
signIn("github", { callbackUrl: "/signup?status=verify" }).then(() =>
setIsLoading(false)
);
}}
Expand All @@ -270,7 +271,7 @@ export function ClientSignupForm({
disabled={isLoading}
onClick={() => {
setIsLoading(true);
signIn("google", { callbackUrl: "/profile" }).then((_) =>
signIn("google", { callbackUrl: "/signup?status=verify" }).then((_) =>
setIsLoading(false)
);
}}
Expand Down
2 changes: 2 additions & 0 deletions apps/web/app/signup/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { Metadata } from "next";
import { authOptions } from "../api/auth/[...nextauth]/util";
import { getServerSession } from "next-auth";
import { redirect } from "next/navigation";
import { responseStatus } from "@paybox/common";
import Error from "./Error";

export const metadata: Metadata = {
title: "PayBox | Signup",
Expand Down

0 comments on commit e234e85

Please sign in to comment.