-
-
Save Nilanth/1ee06af8e59df77c22ce6d4ed7a4d0ab to your computer and use it in GitHub Desktop.
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
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