diff --git a/apps/api/src/controllers/user_controller.ts b/apps/api/src/controllers/user_controller.ts index 3d908fc..925c968 100644 --- a/apps/api/src/controllers/user_controller.ts +++ b/apps/api/src/controllers/user_controller.ts @@ -46,7 +46,7 @@ export async function login_user(req: Request, res: Response): Promise { return } generate_token(res, user._id.toString()) - res.status(200).json(user) + res.status(200).json({ message: 'User logged in successfully' }) } catch (error) { log('Error fetching user:', error) res.status(500).json({ error: 'Internal server error' }) diff --git a/apps/api/src/server.ts b/apps/api/src/server.ts index d9bdb22..72afb11 100644 --- a/apps/api/src/server.ts +++ b/apps/api/src/server.ts @@ -14,7 +14,12 @@ export const createServer = (): Express => { .use(morgan('dev')) .use(urlencoded({ extended: true })) .use(json()) - .use(cors()) + .use( + cors({ + origin: true, + credentials: true, + }) + ) .use(cookieParser()) .get('/health', (_, res) => { return res.json({ ok: true }) diff --git a/apps/frontend/src/app/login/page.tsx b/apps/frontend/src/app/login/page.tsx new file mode 100644 index 0000000..cbe928d --- /dev/null +++ b/apps/frontend/src/app/login/page.tsx @@ -0,0 +1,115 @@ +'use client' + +import { Button } from '@/components/Button' +import { useState } from 'react' + +export default function Login() { + const [error, setError] = useState('') + async function handleSubmit(e: React.FormEvent) { + e.preventDefault() + const formData = new FormData(e.target as HTMLFormElement) + const email = formData.get('email') + const password = formData.get('password') + if (!email || !password) { + return setError('Both fields are required') + } + try { + const response = await fetch( + `${process.env.NEXT_PUBLIC_BASE_API}/user/login`, + { + method: 'POST', + credentials: 'include', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ email, password }), + } + ) + if (!response.ok) { + const data = await response.json() + // throw new Error(data.message) + console.log(data) + setError(data.error) + } + const data = await response.json() + setError('') + console.log(data) + } catch (error) { + setError('some thing went wrong') + } + } + + async function getUser() { + try { + const response = await fetch( + `${process.env.NEXT_PUBLIC_BASE_API}/user/profile`, + { + method: 'GET', + credentials: 'include', + headers: { + 'Content-Type': 'application/json', + }, + } + ) + const data = await response.json() + console.log(data) + } catch (error) { + console.log(error) + } + } + + async function logOutUser() { + try { + const response = await fetch( + `${process.env.NEXT_PUBLIC_BASE_API}/user/logout`, + { + method: 'POST', + credentials: 'include', + headers: { + 'Content-Type': 'application/json', + }, + } + ) + const data = await response.json() + console.log(data) + } catch (error) { + console.log(error) + } + } + + return ( +
+ {/* */} + {/* */} +
+

Login

+
+
+ + +
+
+ + +
+ {error &&

{error}

} + +
+
+
+ ) +} diff --git a/apps/frontend/src/app/post-job/page.tsx b/apps/frontend/src/app/post-job/page.tsx new file mode 100644 index 0000000..fdd54f3 --- /dev/null +++ b/apps/frontend/src/app/post-job/page.tsx @@ -0,0 +1,32 @@ +export default function PostJob() { + return ( +
+
+

Post a Job

+
+ + + + + +
+
+
+ ) +} diff --git a/apps/frontend/src/components/Button.tsx b/apps/frontend/src/components/Button.tsx new file mode 100644 index 0000000..61cbbf2 --- /dev/null +++ b/apps/frontend/src/components/Button.tsx @@ -0,0 +1,26 @@ +export function Button({ + handleClick, + children, + type = 'button', + variant = 'primary', + outline = false, + disabled = false, +}: { + handleClick?: () => void + children: React.ReactNode + type?: 'button' | 'submit' | 'reset' + variant?: 'primary' | 'secondary' + outline?: boolean + disabled?: boolean +}) { + return ( + + ) +} diff --git a/apps/frontend/src/components/Card.tsx b/apps/frontend/src/components/Card.tsx index 94781da..7e8b40a 100644 --- a/apps/frontend/src/components/Card.tsx +++ b/apps/frontend/src/components/Card.tsx @@ -6,7 +6,7 @@ import { Pill } from '.' export function Card({ job }: { job: Job }) { return (