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

Merged
merged 12 commits into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
8,772 changes: 8,772 additions & 0 deletions app/client/package-lock.json
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please we use pnpm instead of npm for app/client.kindly revert

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

app/client still has a package-lock. it should use a pnpm-lock

Large diffs are not rendered by default.

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please restore file as land-registry-backend uses npm. its /app/client that uses pnpm

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 @@ -8,7 +8,7 @@ import { config } from "./config";
const app = express();

// Middleware
app.use(helmet());
// app.use(helmet());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i noticed you commented out this line. might i ask why?

app.use(
cors({
origin: config.corsOrigins,
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',
};
12 changes: 10 additions & 2 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,7 +17,11 @@ 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);
}
Expand Down
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
2 changes: 1 addition & 1 deletion landing_page/src/app/lib/axios.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import axios from "axios";

export const api = axios.create({
baseURL: process.env.NEXT_PUBLIC_API_URL,
baseURL: 'http://localhost:3000',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please dont hardcode the base url

headers: {
"Content-Type": "application/json",
},
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
18 changes: 14 additions & 4 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/server';
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);
// localStorage.setItem("landver_token", res.data.data.token);

toast.success("Signed in successfully!");
setTimeout(() => {
window.location.href = "https://demo.landver.net";
}, 1000);

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


} catch (error) {
const err = error as { response?: { data?: { message?: string } } };
toast.error(err.response?.data?.message || "Failed to sign in");
Expand Down
2 changes: 2 additions & 0 deletions landing_page/src/app/signup/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,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
1 change: 1 addition & 0 deletions node_modules/.bin/cdl

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

1 change: 1 addition & 0 deletions node_modules/.bin/esparse

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

1 change: 1 addition & 0 deletions node_modules/.bin/esvalidate

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

1 change: 1 addition & 0 deletions node_modules/.bin/mime

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

1 change: 1 addition & 0 deletions node_modules/.bin/proto-loader-gen-types

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

1 change: 1 addition & 0 deletions node_modules/.bin/rome

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

1 change: 1 addition & 0 deletions node_modules/.bin/semver

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

1 change: 1 addition & 0 deletions node_modules/.bin/tsc

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

1 change: 1 addition & 0 deletions node_modules/.bin/tsserver

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

Loading
Loading