Skip to content

Instantly share code, notes, and snippets.

@Nilanth
Last active March 15, 2022 17:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nilanth/1ee06af8e59df77c22ce6d4ed7a4d0ab to your computer and use it in GitHub Desktop.
Save Nilanth/1ee06af8e59df77c22ce6d4ed7a4d0ab to your computer and use it in GitHub Desktop.
import axios from 'lib/axios'
import { useNavigate, useParams } from 'react-router-dom';
export const useAuth = () => {
let navigate = useNavigate();
const csrf = () => axios.get('/sanctum/csrf-cookie')
const login = async ({ setErrors, setSuccessResponse }) => {
await csrf()
axios
.post('/login', props)
.then(() => {
setSuccessResponse();
navigate('/dashboard');
});
.catch(error => {
setErrors(error);
})
}
return {
login
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment