diff --git a/client/user-client/src/components/Home.tsx b/client/user-client/src/components/Home.tsx index bc60f9f..5b6d067 100644 --- a/client/user-client/src/components/Home.tsx +++ b/client/user-client/src/components/Home.tsx @@ -3,12 +3,12 @@ export default function Home() {

- Course Selling Platform + Learn Without Limits

- 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.

diff --git a/client/user-client/src/pages/Signin.tsx b/client/user-client/src/pages/Signin.tsx index fbdf3f3..69e7cf0 100644 --- a/client/user-client/src/pages/Signin.tsx +++ b/client/user-client/src/pages/Signin.tsx @@ -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(); @@ -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) { diff --git a/client/user-client/src/serverApi.ts b/client/user-client/src/serverApi.ts index bde3b50..9996cd8 100644 --- a/client/user-client/src/serverApi.ts +++ b/client/user-client/src/serverApi.ts @@ -1 +1 @@ -export const serverApi: string = `http://localhost:8080/user`; +export const serverApi: string = `http://localhost:3000/user`; diff --git a/client/user-client/src/util/DecodeUrl.ts b/client/user-client/src/util/DecodeUrl.ts new file mode 100644 index 0000000..7194c57 --- /dev/null +++ b/client/user-client/src/util/DecodeUrl.ts @@ -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); +} diff --git a/server/src/index.ts b/server/src/index.ts index cf26418..a93aa99 100644 --- a/server/src/index.ts +++ b/server/src/index.ts @@ -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()); diff --git a/server/src/routes/user.ts b/server/src/routes/user.ts index 1998f2b..342c28b 100644 --- a/server/src/routes/user.ts +++ b/server/src/routes/user.ts @@ -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();