-
Notifications
You must be signed in to change notification settings - Fork 2
Integration with Axios
Scott Robertson edited this page Jan 21, 2021
·
1 revision
To use Tokenable via Axios, you could do something like this:
const { data } = await axios.post("https://example.com/api/auth", {
email: "email@example.com",
password: "coolpassword123",
});
const token = data.data.token;
const user_id = data.data.user_id;
You then use this token in all future API requests:
const { data } = await axios.get(`https://example.com/api/user/${user_id}`, {
headers: { Authorization: `Bearer ${token}` },
});