Skip to content

Commit

Permalink
verify route
Browse files Browse the repository at this point in the history
  • Loading branch information
avsomers25 committed Jan 13, 2025
1 parent 2b5b954 commit 38faaaf
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 0 deletions.
71 changes: 71 additions & 0 deletions app/(pre-dashboard)/(entry)/verify/[code]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
"use client"

import { Button } from '@/app/ui/button';


import { Verify } from '../../../../lib/actions';

import { useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import { z } from 'zod';

import { useState } from "react";
import Image from 'next/image';

import { usePathname } from 'next/navigation'

export default function SignupPage() {

const SignUpSchema = z.object({


});

type SignUp = z.infer<typeof SignUpSchema>;


const { register, handleSubmit, reset, formState: { errors }, } = useForm<SignUp>({ resolver: zodResolver(SignUpSchema) });

const [submit_errors, setErrors] = useState("");
const [success, setSuccess] = useState("");

const pathname = usePathname();
const arr = pathname.split("verify/")

console.log(arr[1])

const onSubmit = async (data: SignUp) => {
console.log("SENDING Verify");
console.log(data);
console.log(arr[1])
const resp = await Verify(arr[1]);

console.log(resp);
if (resp.error) {
setErrors(resp.error);
setSuccess("");
} else {
setSuccess(resp.response);
setErrors("");
}

if (resp.error == "Password reset successful") { // for some reason this was showing up as an error
setSuccess(resp.error);
setErrors("");
}
};

return (
<main className="flex items-center justify-center md:h-screen w-screen">
<form onSubmit={handleSubmit(onSubmit)} className='bg-gradient-to-b from-offblack-100 to-[#453148] p-20 rounded-xl'>
<div className="w-full">
{(<p className="text-xs italic text-red-500 mt-2">{submit_errors}</p>)}
{(<p className="text-xs italic text-green-500 mt-2">{success}</p>)}


</div>
<Button type="submit">Verify Email</Button>
</form>
</main>
);
}
39 changes: 39 additions & 0 deletions app/lib/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ const ENDPOINTS = {
* Get the points for the user
*/
points: BASE + '/points',


/**
* verify email after being given a code
*/
verify: BASE + '/verify-email'
};

export async function authenticate(email: string, password: string) {
Expand Down Expand Up @@ -915,3 +921,36 @@ export async function GetPoints() {
}
return resp;
}

export async function Verify(code: string) {
noStore();
let resp = {
error: '',
response: '',
};

await fetch(ENDPOINTS.verify, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
code: code,
}),
}).then(async (res) => {
let resJSON = await res.json();
if (resJSON.statusCode === 403) {
resp.error = 'Invalid code';
} else if (resJSON.statusCode === 200) {
resp.response = resJSON.message;
} else {
if (resJSON.message) {
resp.error = resJSON.message;
} else {
resp.error = 'Unexpected Error';
}
}
});

return resp;
}

0 comments on commit 38faaaf

Please sign in to comment.