-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5b5cd3b
commit d717f07
Showing
15 changed files
with
308 additions
and
195 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { NextRequest, NextResponse } from "next/server"; | ||
import { getDataToken } from "@/utils/getDataToken"; | ||
|
||
export async function GET(request: NextRequest) { | ||
try { | ||
await getDataToken(request); | ||
return NextResponse.json({ authenticated: true }); | ||
} catch (error: any) { | ||
return NextResponse.json( | ||
{ error: error.message, status: 500 }, | ||
{ status: 500 } | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,58 @@ | ||
'use client'; | ||
"use client"; | ||
|
||
import Button from "@/components/Button"; | ||
import TextInput from "@/components/TextInput"; | ||
import APICaller from "@/utils/APICaller"; | ||
import { useRouter } from "next/navigation"; | ||
import { useState } from "react"; | ||
|
||
export default function Login() { | ||
const [email, setEmail] = useState(""); | ||
const [password, setPassword] = useState(""); | ||
const [name, setName] = useState(""); | ||
const [email, setEmail] = useState(""); | ||
const [password, setPassword] = useState(""); | ||
|
||
const router = useRouter(); | ||
const router = useRouter(); | ||
|
||
async function handleLogin() { | ||
if (!email || !password) { | ||
return; | ||
} | ||
try { | ||
const requestData = { email, password }; | ||
const response = await APICaller("/api/login", "POST", requestData); | ||
if (response.success) { | ||
localStorage.setItem("token", response.token); | ||
} | ||
} catch (error) { | ||
console.error("Erro ao fazer login:", error); | ||
} | ||
async function handleLogin() { | ||
if (!email || !password) { | ||
return; | ||
} | ||
|
||
async function handleRegister() { | ||
if (!email || !password || !name) { | ||
return; | ||
} | ||
try { | ||
const requestData = { email, password, name }; | ||
const response = await APICaller("/api/register", "POST", requestData); | ||
if (response.success) { | ||
localStorage.setItem("token", response.token); | ||
router.push("/dashboard"); | ||
} | ||
} catch (error) { | ||
console.error("Error ao registrar:", error); | ||
} | ||
}; | ||
|
||
async function helloWorld() { | ||
try { | ||
const response = await APICaller("/api/helloworld", "GET"); | ||
} catch (error) { | ||
console.error("Error:", error); | ||
} | ||
try { | ||
const requestData = { email, password }; | ||
const response = await APICaller("/api/login", "POST", requestData); | ||
if (response.success) { | ||
localStorage.setItem("token", response.token); | ||
} | ||
} catch (error) { | ||
console.error("Erro ao fazer login:", error); | ||
} | ||
|
||
return ( | ||
<div> | ||
<input | ||
type="text" | ||
placeholder="Email" | ||
value={email} | ||
onChange={(e) => setEmail(e.target.value)} | ||
/> | ||
<input | ||
type="text" | ||
placeholder="Name" | ||
value={name} | ||
onChange={(e) => setName(e.target.value)} | ||
/> | ||
<input | ||
type="password" | ||
placeholder="Senha" | ||
value={password} | ||
onChange={(e) => setPassword(e.target.value)} | ||
/> | ||
<button onClick={handleLogin} className="mr-10">Login</button> | ||
<button onClick={handleRegister} className="mr-10">Register</button> | ||
<button onClick={helloWorld} className="mr-10">hello world (needs auth)</button> | ||
} | ||
|
||
return ( | ||
<div className="flex w-full h-full justify-center items-center"> | ||
<div className="flex flex-col w-96 shadow-xl p-10 rounded-lg gap-2"> | ||
<TextInput | ||
setName={setEmail} | ||
value={email} | ||
type="email" | ||
label="Email" | ||
placeholder="[email protected]" | ||
/> | ||
<TextInput | ||
setName={setPassword} | ||
value={password} | ||
type="password" | ||
label="Senha" | ||
placeholder="•••••••••" | ||
/> | ||
<div className="flex gap-2 mt-4"> | ||
<Button | ||
text="Registrar-se" | ||
onClick={() => router.push("/register")} | ||
style="outline" | ||
></Button> | ||
<Button text="Entrar" onClick={handleLogin} style="primary"></Button> | ||
</div> | ||
) | ||
|
||
} | ||
</div> | ||
</div> | ||
); | ||
} |
Oops, something went wrong.