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

Init NextJS #16

Merged
merged 8 commits into from
Apr 27, 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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
login page with dummy api
  • Loading branch information
Monstarrrr committed Apr 27, 2024
commit 2b152c3f73ee77da6cb6ed4c3a262b5eef900531
2 changes: 1 addition & 1 deletion backend/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ services:
web:
build: .
ports:
- "8000:8000"
- '8000:8000'
env_file:
- .env
56 changes: 55 additions & 1 deletion frontend/app/(auth)/login/page.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,57 @@
'use client'

import { FormEvent } from 'react'
import { useRouter } from 'next/navigation'

export default function LoginPage() {
return <p>Login page</p>
const router = useRouter()

async function handleSubmit(event: FormEvent<HTMLFormElement>) {
event.preventDefault()

const formData = new FormData(event.currentTarget)
const username = formData.get('username')
const password = formData.get('password')

const response = await fetch(
'https://dummyjson.com/auth/login',
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
username,
password,
}),
},
)

if (response.ok) {
alert('Login successful')
router.push('/')
} else {
throw new Error('Failed to login')
}
}

return (
<form onSubmit={handleSubmit}>
<input
type='text'
name='username'
placeholder='Username'
value='kminchelle'
required
/>
<input
type='password'
name='password'
placeholder='Password'
value='0lelplR'
required
/>
<button type='submit'>Login</button>
</form>
)
}
13 changes: 10 additions & 3 deletions frontend/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ export default function Home() {
<h2>
Docs <span>-&gt;</span>
</h2>
<p>Find in-depth information about Next.js features and API.</p>
<p>
Find in-depth information about Next.js features and
API.
</p>
</a>

<a
Expand All @@ -61,7 +64,10 @@ export default function Home() {
<h2>
Learn <span>-&gt;</span>
</h2>
<p>Learn about Next.js in an interactive course with&nbsp;quizzes!</p>
<p>
Learn about Next.js in an interactive course
with&nbsp;quizzes!
</p>
</a>

<a
Expand All @@ -86,7 +92,8 @@ export default function Home() {
Deploy <span>-&gt;</span>
</h2>
<p>
Instantly deploy your Next.js site to a shareable URL with Vercel.
Instantly deploy your Next.js site to a shareable URL
with Vercel.
</p>
</a>
</div>
Expand Down