johnvictorfs / rsatlantis

Website for the RuneScape Clan Atlantis made with Django and Vue.js. Backend Repository
https://atlantis.jvfs.dev/api/docs/swagger
GNU Affero General Public License v3.0
1 stars 1 forks source link

Atualizar API para usar intercepts para autenticação #24

Closed johnvictorfs closed 4 years ago

johnvictorfs commented 5 years ago

Usar o formato abaixo:

api.interceptors.request.use(async config => {
  const token = localStorage.getItem('TOKEN')
  if (token) {
    config.headers.Authorization = `Token ${token}`
  }
  return config
})

Código: https://github.com/johnvictorfs/rsatlantis/blob/dev/frontend/src/api/index.ts#L14-L16

Considerar mover Token para cookies ao invés de localStorage

Fonte: https://blog.rocketseat.com.br/reactjs-autenticacao/