(token, dispatch)
| 181 | } |
| 182 | |
| 183 | export function receiveToken(token, dispatch) { |
| 184 | let user; |
| 185 | |
| 186 | // We check if app runs with backend mode |
| 187 | if (config.isBackend) { |
| 188 | user = decodeJwtPayload(token)?.user || {}; |
| 189 | } else { |
| 190 | user = { |
| 191 | email: config.auth.email, |
| 192 | }; |
| 193 | } |
| 194 | |
| 195 | if (user && typeof user === 'object') { |
| 196 | delete user.id; |
| 197 | } |
| 198 | localStorage.setItem('token', token); |
| 199 | localStorage.setItem('user', JSON.stringify(user)); |
| 200 | localStorage.setItem('theme', 'default'); |
| 201 | axios.defaults.headers.common['Authorization'] = 'Bearer ' + token; |
| 202 | dispatch({ type: 'LOGIN_SUCCESS' }); |
| 203 | } |
| 204 | |
| 205 | async function findMe() { |
| 206 | if (config.isBackend) { |
no test coverage detected