-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from alura-challenges/aula05
Final aula 05
- Loading branch information
Showing
3 changed files
with
116 additions
and
2 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import React from 'react'; | ||
// Hook do NextJS | ||
import { useRouter } from 'next/router'; | ||
import nookies from 'nookies'; | ||
|
||
export default function LoginScreen() { | ||
const router = useRouter(); | ||
const [githubUser, setGithubUser] = React.useState('omariosouto'); | ||
|
||
return ( | ||
<main style={{ display: 'flex', flex: 1, alignItems: 'center', justifyContent: 'center' }}> | ||
<div className="loginScreen"> | ||
<section className="logoArea"> | ||
<img src="https://alurakut.vercel.app/logo.svg" /> | ||
|
||
<p><strong>Conecte-se</strong> aos seus amigos e familiares usando recados e mensagens instantâneas</p> | ||
<p><strong>Conheça</strong> novas pessoas através de amigos de seus amigos e comunidades</p> | ||
<p><strong>Compartilhe</strong> seus vídeos, fotos e paixões em um só lugar</p> | ||
</section> | ||
|
||
<section className="formArea"> | ||
<form className="box" onSubmit={(infosDoEvento) => { | ||
infosDoEvento.preventDefault(); | ||
// alert('Alguém clicou no botão!') | ||
console.log('Usuário: ', githubUser) | ||
fetch('https://alurakut.vercel.app/api/login', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json' | ||
}, | ||
body: JSON.stringify({ githubUser: githubUser }) | ||
}) | ||
.then(async (respostaDoServer) => { | ||
const dadosDaResposta = await respostaDoServer.json() | ||
const token = dadosDaResposta.token; | ||
nookies.set(null, 'USER_TOKEN', token, { | ||
path: '/', | ||
maxAge: 86400 * 7 | ||
}) | ||
router.push('/') | ||
}) | ||
}}> | ||
<p> | ||
Acesse agora mesmo com seu usuário do <strong>GitHub</strong>! | ||
</p> | ||
<input | ||
placeholder="Usuário" | ||
value={githubUser} | ||
onChange={(evento) => { | ||
setGithubUser(evento.target.value) | ||
}} | ||
/> | ||
{githubUser.length === 0 | ||
? 'Preencha o campo' | ||
: '' | ||
} | ||
<button type="submit"> | ||
Login | ||
</button> | ||
</form> | ||
|
||
<footer className="box"> | ||
<p> | ||
Ainda não é membro? <br /> | ||
<a href="/login"> | ||
<strong> | ||
ENTRAR JÁ | ||
</strong> | ||
</a> | ||
</p> | ||
</footer> | ||
</section> | ||
|
||
<footer className="footerArea"> | ||
<p> | ||
© 2021 alura.com.br - <a href="/">Sobre o Orkut.br</a> - <a href="/">Centro de segurança</a> - <a href="/">Privacidade</a> - <a href="/">Termos</a> - <a href="/">Contato</a> | ||
</p> | ||
</footer> | ||
</div> | ||
</main> | ||
) | ||
} |
b6d992f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: