react-simple-cookie-store
v1.0.12
Published
A simple cookie store built on top of universal-cookie.
Downloads
391
Readme
~~React~~ Simple Cookie Store
A dead simple interface for storing cookies. Built on top of universal-cookies and luxon. Automatically sets cookies as secure provided the user is browsing via HTTPS. To illustrate usage, check out this simple example storing an access token:
import { setCookie, getCookie, removeCookie } from "react-simple-cookie-store"
// Do some work...
async function login(email,password) {
let token = await authenticate(username,password)
// Sets a cookie to store some value (i.e. accessToken) which will be valid for 2 days.
setCookie("token", token, 2)
}
// Retrieves the stored accessToken.
function currentUser() {
return getCookie("token")
}
// Clear the cookie storing the current user's access token.
function logout() {
removeCookie("token")
}