Skip to content

Instantly share code, notes, and snippets.

@shibbirweb
Created April 22, 2020 11:39
Show Gist options
  • Select an option

  • Save shibbirweb/a2a35c1b576e8778ab90d2b9995aef63 to your computer and use it in GitHub Desktop.

Select an option

Save shibbirweb/a2a35c1b576e8778ab90d2b9995aef63 to your computer and use it in GitHub Desktop.
Smart way to use API
import axios from 'axios';
import store from "../store"
// api version 1
const baseAPI = axios.create({
baseURL: `http://yoursite.test/api/v1`
});
// configure api
let api = () => {
// get token
const token = store.getters["auth/token"];
// if has token
if (token) {
// set token in authorization
baseAPI.defaults.headers.common['Authorization'] = `Bearer ${token}`
}
return baseAPI;
}
export default api;
import api from "../api";
// register
export const register = (data) => {
return api().post('register', data)
}
// email verify
export const verifyEmail = (url) => {
return api().post(url,{}, {
'baseURL': ''
})
}
// login
export const login = (data) => {
return api().post('login', data)
}
// logout
export const logout = () => {
return api().post('logout')
}
// send password reset email
export const sendPasswordResetEmail = (email) => {
return api().post('password/email', {email})
}
// reset password
export const passwordReset = (data) => {
return api().post('password/reset', data)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment