Skip to content

Instantly share code, notes, and snippets.

@onedebos
Last active March 26, 2022 01:22
Show Gist options
  • Save onedebos/93ef2818c4028c315daf74d0f20655f7 to your computer and use it in GitHub Desktop.
Save onedebos/93ef2818c4028c315daf74d0f20655f7 to your computer and use it in GitHub Desktop.
// pages/login.js
import { useCookies } from "react-cookie"
const Login = () => {
const [cookie, setCookie] = useCookies(["user"])
const handleSignIn = async () => {
try {
const response = await yourLoginFunction(username) //handle API call to sign in here.
const data = response.data
setCookie("user", JSON.stringify(data), {
path: "/",
maxAge: 3600, // Expires after 1hr
sameSite: true,
})
} catch (err) {
console.log(err)
}
}
return (
<>
<label htmlFor="username">
<input type="text" placeholder="enter username" />
</label>
</>
)
}
export default Login
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment