Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

landing page redirect #249

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
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
8,772 changes: 8,772 additions & 0 deletions app/client/package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions land-registry-backend/package-lock.json

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

2 changes: 1 addition & 1 deletion land-registry-backend/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { config } from "./config";

const app = express();

// Middleware
Middleware
app.use(helmet());
app.use(
cors({
Expand Down
3 changes: 2 additions & 1 deletion land-registry-backend/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ dotenv.config();
export const config = {
port: process.env.PORT || 3000,
databaseUrl: process.env.DATABASE_URL || '',
ssl: false,
environment: process.env.NODE_ENV || 'development',
corsOrigins: process.env.CORS_ORIGINS?.split(',') || ['http://localhost:3000'],
corsOrigins: process.env.CORS_ORIGINS?.split(',') || ['http://localhost:3001'],
jwtSecret: process.env.JWT_SECRET || 'your-default-secret-key',
};
33 changes: 30 additions & 3 deletions land-registry-backend/src/controllers/authController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import * as authService from '../services/authService';
export async function register(req: Request, res: Response, next: NextFunction) {
try {
const user = await authService.register(req.body);
res.status(201).json(user);
res.status(201).json({
status: "success",
message: "User signed in successfully",
data: user
});
} catch (error) {
next(error);
}
Expand All @@ -13,8 +17,31 @@ export async function register(req: Request, res: Response, next: NextFunction)
export async function login(req: Request, res: Response, next: NextFunction) {
try {
const result = await authService.login(req.body);
res.json(result);
res.status(201).json({
status: "success",
message: "User logged successfully",
data: result
});
} catch (error) {
next(error);
}
}
}


//Logout user
export const logoutUser =
async (req: Request, res: Response, next: NextFunction) => {
try {
res.cookie("landver_token", "", { maxAge: 1 });
// res.cookie("refresh_token", "", { maxAge: 1 });

const userId = req.user?._id || "";

res.status(200).json({
success: true,
message: "Logged Out successfully",
});
} catch (error: any) {
return next(error);
}
}
35 changes: 32 additions & 3 deletions land-registry-backend/src/services/authService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ import { query } from "./db";
import { RegisterDTO, LoginDTO, User } from "../types/auth";
import { AppError } from "../middleware/errorHandler";
import { config } from "../config";
import dotenv from "dotenv";
dotenv.config();

export async function register(data: RegisterDTO): Promise<User> {
export async function register(
data: RegisterDTO
): Promise<{ token: string; user: User }> {
// Check if user already exists
const existingUser = await query(
"SELECT * FROM users WHERE email = $1 OR wallet_address = $2",
Expand All @@ -30,7 +34,32 @@ export async function register(data: RegisterDTO): Promise<User> {
[data.email, passwordHash, data.walletAddress, data.userType]
);

return result.rows[0];
const user: User = result.rows[0];

const token = jwt.sign(
{
email: user.email,
walletAddress: user.walletAddress,
userType: user.userType,
},
config.jwtSecret,
{ expiresIn: "1h" } // Token expires in 1 hour
);

console.log(token);

// Return the user and token
return {
user: {
id: user.id,
email: user.email,
walletAddress: user.walletAddress,
userType: user.userType,
createdAt: user.createdAt,
updatedAt: user.updatedAt,
},
token,
};
}

export async function login(
Expand Down Expand Up @@ -58,7 +87,7 @@ export async function login(
config.jwtSecret,
{ expiresIn: "24h" }
);

return {
token,
user: {
Expand Down
1 change: 1 addition & 0 deletions land-registry-backend/src/services/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Pool } from 'pg';
import { config } from '../config';

export const pool = new Pool({

connectionString: config.databaseUrl,
ssl: {
rejectUnauthorized: false
Expand Down
30 changes: 26 additions & 4 deletions landing_page/package-lock.json

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

1 change: 1 addition & 0 deletions landing_page/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"@radix-ui/react-select": "^2.1.2",
"axios": "^1.7.8",
"clsx": "^2.1.1",
"cookies-next": "^5.0.2",
"lucide-react": "^0.453.0",
"next": "14.2.15",
"next-themes": "^0.3.0",
Expand Down
14 changes: 14 additions & 0 deletions landing_page/src/app/middleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// import { NextResponse, NextRequest } from 'next/server'

// export function middleware(request: NextRequest) {

// const accessToken = request.cookies.get('access-token')

// console.log( accessToken )

// const response = NextResponse.next()

// response.cookies.set('access-token', 'Your secret token')

// return response
// }
18 changes: 17 additions & 1 deletion landing_page/src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,35 @@
"use client";
import Navbar from "./components/NavBar";
import Hero from "./components/Hero";
import WhyChooseLandVer from "./components/WhyChooseLandver";
import Footer from "./components/Footer";
import RegisterCTA from "./components/RegisterCTA";
import Benefits from "./components/Benefits";
import NewsLetterCTA from "./components/NewsLetterCTA";
import { getCookie } from "cookies-next/server";
import { useEffect } from "react";
import { useRouter } from "next/navigation";

export default function Home() {
const router = useRouter();


// useEffect(() => {
// const isLoggedIn = getCookie("landver_token");

// if (isLoggedIn) {
// router.push("https://demo.landver.net/");
// }
// }, [router]);

return (
<div className="bg-[#f5f5f5] text-[#1f1f1f]">
<Navbar />
<Hero />
<RegisterCTA />
<WhyChooseLandVer />
<Benefits />
<NewsLetterCTA/>
<NewsLetterCTA />
<Footer />
</div>
);
Expand Down
20 changes: 15 additions & 5 deletions landing_page/src/app/signin/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,34 @@ import { toast } from "react-toastify";
import Button from "../components/Button/Button";
import { Input } from "../components/Input/Input";
import { ToastContainer } from "react-toastify";
import { useRouter } from "next/navigation";
import { api } from "../lib/axios";
import { setCookie } from 'cookies-next/client';
import "react-toastify/dist/ReactToastify.css";


export default function LoginPage() {
const [showPassword, setShowPassword] = useState(false);
const [loading, setLoading] = useState(false);
const [email, setEmail] = useState("");
const [passcode, setPasscode] = useState("");

const router = useRouter();

const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
setLoading(true);
try {
await api.post("/auth/login", { email, passcode });
const res = await api.post("/auth/login", { email, passcode });

setCookie('landver_token', res.data.data.token, {maxAge: 5});
// localStorage.setItem("landver_token", res.data.data.token);

toast.success("Signed in successfully!")

router.push("https://demo.landver.net")


toast.success("Signed in successfully!");
setTimeout(() => {
window.location.href = "https://demo.landver.net";
}, 1000);
} catch (error) {
const err = error as { response?: { data?: { message?: string } } };
toast.error(err.response?.data?.message || "Failed to sign in");
Expand Down
14 changes: 12 additions & 2 deletions landing_page/src/app/signup/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ import {
SelectTrigger,
SelectValue,
} from "../components/Select/Select";
import { useRouter } from "next/navigation";
import { api } from "../lib/axios";
import { setCookie } from 'cookies-next/client';
import { ToastContainer } from "react-toastify";
import "react-toastify/dist/ReactToastify.css";
import { toast } from "react-toastify";

export default function SignupPage() {
const router = useRouter();
const [showPassword, setShowPassword] = useState(false);
const [showConfirmPassword, setShowConfirmPassword] = useState(false);

Expand Down Expand Up @@ -48,10 +51,15 @@ export default function SignupPage() {
userType: formData.role,
});

localStorage.setItem("token", response.data.token);


// localStorage.setItem("token", response.data.token);

setCookie('landver_token', response.data.data.token);

toast.success("Registration successful!");
setTimeout(() => {
window.location.href = "https://demo.landver.net";
router.push("https://demo.landver.net")
}, 1000);
} catch (err: unknown) {
const error = err as { response?: { data?: { message?: string } } };
Expand All @@ -75,6 +83,8 @@ export default function SignupPage() {
});
};



return (
<div className="min-h-screen flex items-center justify-center bg-[#f5f5f5] text-[#1f1f1f] px-4">
<ToastContainer theme="colored" />
Expand Down
Loading
Loading