Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/context/auth-context.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, { createContext, useState, useLayoutEffect, useContext, useCallback } from 'react'
import { useAsync } from 'react-async'

import { login as authLogin } from 'services/auth'
import { setAccessToken, setRefreshToken, clearToken, bootstrapAppData } from 'helpers'
import { authServices } from 'services/auth'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tu não curte importar direto de services?

Como o import já é nominal, não vejo pq não importar do index (pensando também no padrão que já usamos). No entanto, sei que já tivemos algumas discussões inacabadas sobre esse assunto, então resolvi levantar o questionamento aqui para chegarmos em uma conclusão.

De qualquer forma, curti o approach!


import Loader from 'components/Loader'

Expand All @@ -22,7 +22,7 @@ const AuthProvider = props => {

const login = useCallback(async data => {
try {
const { access_token, refresh_token, ...user } = await authLogin(data)
const { access_token, refresh_token, ...user } = await authServices.login(data)
setAccessToken(access_token)
setRefreshToken(refresh_token)
reload()
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/bootstrap.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as Sentry from '@sentry/browser'

import { getUser } from 'services/auth'
import { authServices } from 'services/auth'
import { getToken } from 'helpers'

const bootstrapAppData = async () => {
Expand All @@ -10,7 +10,7 @@ const bootstrapAppData = async () => {
return { user: null }
}

const user = await getUser()
const user = await authServices.getUser()

if (process.env.REACT_APP_NODE_ENV === 'production') {
Sentry.configureScope(scope =>
Expand Down
9 changes: 7 additions & 2 deletions src/services/auth.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import client from 'providers/fetchClient'

export const getUser = () => client.get('/v1/me')
const getUser = () => client.get('/v1/me')

export const login = data => client.post('/v1/users/login', data)
const login = async data => {
const { token, ...user } = await client.post('/v1/users/login', data)
return { token, user }
}

export const authServices = { getUser, login }