Skip to content

Instantly share code, notes, and snippets.

@vouill
vouill / main.js
Created December 4, 2017 11:16
auth main
const token = localStorage.getItem('user-token')
if (token) {
axios.defaults.headers.common['Authorization'] = token
}
@vouill
vouill / app.js
Created December 4, 2017 11:19
app.vue mehtod handling unauthorize
created: function () {
axios.interceptors.response.use(undefined, function (err) {
return new Promise(function (resolve, reject) {
if (err.status === 401 && err.config && !err.config.__isRetryRequest) {
// if you ever get an unauthorized, logout the user
this.$store.dispatch(AUTH_LOGOUT)
// you can also redirect to /login if needed !
}
throw err;
});
@vouill
vouill / app.js
Created April 29, 2019 08:32
Preparing SQL queries
// before
db.all(`SELECT * FROM POSTS WHERE ID = ${req.params.id};`, function(
err,
row
) {
res.send(row);
});
// after