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

dev #41

Merged
merged 2 commits into from
Jan 12, 2024
Merged

dev #41

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 changes: 4 additions & 4 deletions client/user-client/src/components/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ export default function Home() {
<div className="">
<div className="">
<h1 className="text-[#1E0E62] text-center text-7xl font-bold mt-36">
Course Selling Platform
Learn Without Limits
</h1>
<p className="text-[#151439] text-center text-xl font-medium max-w-xl mx-auto mt-12">
We made it so beautiful and simple. It combines courses, adds courses,
updates and deletes. So you can focus on the teaching part. It is
definitely the tool you need in your collection!
Start, switch, or advance your career with more than 5,800 courses,
Professional Certificates, and degrees from world-class universities
and companies.
</p>
</div>
</div>
Expand Down
8 changes: 7 additions & 1 deletion client/user-client/src/pages/Signin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useState } from "react";
import { useNavigate } from "react-router-dom";
import { serverApi } from "../serverApi";
import { Link } from "react-router-dom";
import base64UrlDecoded from "../util/DecodeUrl";

export default function Signin() {
const navigate = useNavigate();
Expand All @@ -22,7 +23,12 @@ export default function Signin() {
body: JSON.stringify({ email, password }),
});
if (response.ok) {
console.log(response.headers.get("userAccessToken"));
const cookieFromDocument = document.cookie;
const userAccessCookie = cookieFromDocument.split("=");
const userJWT = userAccessCookie[1];
const [header, payload, signature] = userJWT.split(".");
const decodedPayloadData = JSON.parse(base64UrlDecoded(payload));
console.log(decodedPayloadData);
navigate("/");
}
if (response.status === 401 || response.status === 404) {
Expand Down
2 changes: 1 addition & 1 deletion client/user-client/src/serverApi.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const serverApi: string = `http://localhost:8080/user`;
export const serverApi: string = `http://localhost:3000/user`;
8 changes: 8 additions & 0 deletions client/user-client/src/util/DecodeUrl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default function base64UrlDecoded(base64Url: any) {
const base64 = base64Url.replace(/-/g, "+").replace(/_/g, "/");
const paddedBase64 = base64.padEnd(
base64.length + ((4 - (base64.length % 4)) % 4),
"=",
);
return atob(paddedBase64);
}
7 changes: 3 additions & 4 deletions server/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import express, { Request, Response, Express } from "express";
import dotenv from "dotenv";
import path from "path";
import cookieParser from "cookie-parser";
import { adminRouter } from "./routes/admin.ts";
import { userRouter } from "./routes/user.ts";
import { adminRouter } from "./routes/admin";
import { userRouter } from "./routes/user";
import cors from "cors";

dotenv.config({
override: true,
path: path.join(__dirname, "../.env"),
path: `${__dirname}/../.env`,
});
const app: Express = express();
app.use(express.json());
Expand Down
5 changes: 2 additions & 3 deletions server/src/routes/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,14 @@ userRouter.post("/signin", async (req: Request, res: Response) => {
userData;
const userPayload: userPayload = { id, email, role };
const userToken: string = generateUserJWT(userPayload);
// res.setHeader("Set-Cookie", [`userAccessToken=${userToken}`])
res.cookie("userAccessToken", userToken, {
domain: "localhost",
path: "/",
maxAge: 60 * 60 * 1000,
secure: true,
sameSite: "strict",
});
}
return res.json({ message: "Logged in successfully", email });
return res.json({ message: "Logged in successfully" });
}
} catch (error) {
await prisma.$disconnect();
Expand Down