I learn Santum and I want to make system of authorize. I made login controller and it return a token but I need send token to the server. I read that the best way is using httpOnly cookie.Look at this example
function Login () {
const emailRef = useRef(),
passwordRef = useRef();
const [cookies, setCookie] = useCookies();
const handleSubmit = (event) => {
event.preventDefault();
instance.post('/api/auth/login', {
email: emailRef.current.value,
password: passwordRef.current.value
}).then(res => {
console.log(res.data.access_token);
setCookie('Authorize', res.data.access_token, {
httpOnly: true
})
})
}
return(
<div>
<form onSubmit={handleSubmit}>
<input ref={emailRef} type="text" />
<input type="password" ref={passwordRef} placeholder="password" />
<button role="submit">Wyślij</button>
</form>
<Router>
<div>
<nav>
<ul>
<li>
<Link to="/about">About</Link>
</li>
<li>
<Link to="/me">About</Link>
</li>
</ul>
</nav>
<Switch>
<Route path="/about">
<About />
</Route>
</Switch>
</div>
</Router>
</div>
);
}
At this example I send request and next I get a token from server. So how can I send cookie in header (becouse I should do that to autorize my request, am I?)