Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions frontend/app/context/Context.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"use client"
import React, { createContext, useContext, useState, ReactNode } from "react";

interface AuthContextType {
currentUser: any; // You should replace 'any' with the actual type of currentUser
setCurrentUser: (currentUser: any) => void; // You should replace 'any' with the actual type of currentUser
token: string;
setToken: (token: string) => void;
}

export const AuthContext = createContext<AuthContextType | undefined>(
undefined
);

// our hook
export const useAuth = () => {
const context = useContext(AuthContext);
if (!context) {
throw new Error("useAuth must be used within an AuthProvider");
}
return context;
};

export const AuthProvider: React.FC<{ children: ReactNode }> = ({
children,
}) => {
const [currentUser, setCurrentUser] = useState<any>(null); // You should replace 'any' with the actual type of currentUser
const [token, setToken] = useState<string>("");

const value: AuthContextType = {
currentUser,
setCurrentUser,
token,
setToken,
};

return <AuthContext.Provider value={value}> {children}</AuthContext.Provider>;
};
5 changes: 4 additions & 1 deletion frontend/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Metadata } from "next";
import { Inter } from "next/font/google";
import "./globals.css";
import { AuthProvider } from "./context/Context";

const inter = Inter({ subsets: ["latin"] });

Expand All @@ -16,7 +17,9 @@ export default function RootLayout({
}>) {
return (
<html lang="en">
<body className={inter.className}>{children}</body>
<body className={inter.className}>
<AuthProvider>{children}</AuthProvider>
</body>
</html>
);
}
116 changes: 72 additions & 44 deletions frontend/app/signup/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,53 +7,81 @@ import axios from "axios";
import { useState } from "react";
import { BACKEND_URL } from "../config";
import { useRouter } from "next/navigation";
import { useAuth } from "../context/Context";

export default function() {
const router = useRouter();
const [name, setName] = useState("");
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
export default function () {
const router = useRouter();
const [name, setName] = useState("");
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
const { token, setToken } = useAuth();

return <div>
<Appbar />
<div className="flex justify-center">
<div className="flex pt-8 max-w-4xl">
<div className="flex-1 pt-20 px-4">
<div className="font-semibold text-3xl pb-4">
Join millions worldwide who automate their work using Zapier.
</div>
<div className="pb-6 pt-4">
<CheckFeature label={"Easy setup, no coding required"} />
</div>
<div className="pb-6">
<CheckFeature label={"Free forever for core features"} />
</div>
<CheckFeature label={"14-day trial of premium features & apps"} />

</div>
<div className="flex-1 pt-6 pb-6 mt-12 px-4 border rounded">
<Input label={"Name"} onChange={e => {
setName(e.target.value)
}} type="text" placeholder="Your name"></Input>
<Input onChange={e => {
setEmail(e.target.value)
}} label={"Email"} type="text" placeholder="Your Email"></Input>
<Input onChange={e => {
setPassword(e.target.value)
}} label={"Password"} type="password" placeholder="Password"></Input>
return (
<div>
<Appbar />
<div className="flex justify-center">
<div className="flex pt-8 max-w-4xl">
<div className="flex-1 pt-20 px-4">
<div className="font-semibold text-3xl pb-4">
Join millions worldwide who automate their work using Zapier.
</div>
<div className="pb-6 pt-4">
<CheckFeature label={"Easy setup, no coding required"} />
</div>
<div className="pb-6">
<CheckFeature label={"Free forever for core features"} />
</div>
<CheckFeature label={"14-day trial of premium features & apps"} />
</div>
<div className="flex-1 pt-6 pb-6 mt-12 px-4 border rounded">
<Input
label={"Name"}
onChange={(e) => {
setName(e.target.value);
}}
type="text"
placeholder="Your name"
></Input>
<Input
onChange={(e) => {
setEmail(e.target.value);
}}
label={"Email"}
type="text"
placeholder="Your Email"
></Input>
<Input
onChange={(e) => {
setPassword(e.target.value);
}}
label={"Password"}
type="password"
placeholder="Password"
></Input>

<div className="pt-4">
<PrimaryButton onClick={async () => {
const res = await axios.post(`${BACKEND_URL}/api/v1/user/signup`, {
username: email,
password,
name
});
router.push("/login");
}} size="big">Get started free</PrimaryButton>
</div>
</div>
<div className="pt-4">
<PrimaryButton
onClick={async () => {
const res = await axios.post(
`${BACKEND_URL}/api/v1/user/signup`,
{
username: email,
password,
name,
}
);
console.log(res.data.token);
setToken(res.data.token);
router.push("/verify");
}}
size="big"
>
Get started free
</PrimaryButton>
</div>
</div>
</div>
</div>
</div>
}
);
}
60 changes: 60 additions & 0 deletions frontend/app/verify/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
"use client";
import { Appbar } from "@/components/Appbar";
import { CheckFeature } from "@/components/CheckFeature";
import { Input } from "@/components/Input";
import { PrimaryButton } from "@/components/buttons/PrimaryButton";
import axios from "axios";
import { useState } from "react";
import { BACKEND_URL } from "../config";
import { useRouter } from "next/navigation";
import { useAuth } from "../context/Context";

export default function () {
const { token } = useAuth();

console.log("token", token);
const [activationCode, setActivationCode] = useState("");
const router = useRouter();

return (
<div>
<Appbar />
<div className="flex justify-center">
<div className="flex pt-8 max-w-4xl">
<div className="flex-1 pt-6 pb-6 mt-12 px-4 border rounded w-96 h-80">
<h1 className="font-semibold text-2xl text-center ">
Verify your Account
</h1>
<div className="pt-8"></div>
<Input
onChange={(e) => {
setActivationCode(e.target.value);
}}
label={""}
type="password"
placeholder="code"
></Input>

<div className="pt-10">
<PrimaryButton
onClick={async () => {
const res = await axios.post(
`${BACKEND_URL}/api/v1/user/verify-user`,
{
token: token,
activationCode: activationCode,
}
);
router.push("/login");
}}
size="big"
>
Verify
</PrimaryButton>
</div>
</div>
</div>
</div>
</div>
);
}
91 changes: 91 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading