| @@ -62,7 +62,7 @@ const LoginPage = ({ history }) => { | |||
| dispatch(clearLoginErrors()); | |||
| dispatch( | |||
| fetchUser({ | |||
| email, | |||
| identifier: email, | |||
| password, | |||
| handleApiResponseSuccess, | |||
| }) | |||
| @@ -17,12 +17,13 @@ export default { | |||
| }, | |||
| authentications: { | |||
| getUsernames: 'authenticate/usernames', | |||
| login: 'auth/token', | |||
| login: 'api/auth/local', | |||
| register: 'api/auth/local/register', | |||
| getUserSecurityQuestion: 'users/username/securityquestion', | |||
| confirmSecurityQuestion: 'authenticate/confirm', | |||
| confirmForgotPassword: 'users/passwords/reset_token', | |||
| resetPassword: 'users/passwords', | |||
| refreshToken: 'auth/refresh', | |||
| refreshToken: 'api/token/refresh', | |||
| generateToken: '/authenticate/generate', | |||
| authenticate: | |||
| '/authenticate?fp={fp}&offer={offer}&landingPageUrl={landingPageUrl}®istrationFlowType={registrationFlowType}', | |||
| @@ -108,7 +109,7 @@ export default { | |||
| getRegistrationAccounts: '/users/{userUid}/accounts', | |||
| updateUser: '/users/{userUid}?updateUserActionType={actionType}', | |||
| updateUserPassword: '/users/{userUid}/passwords', | |||
| logout: 'auth/logout', | |||
| logout: 'api/auth/logout', | |||
| getUsernames: '/users/email', | |||
| createUser: | |||
| '/users?fp={fp}&offer={offer}&landingPageUrl={landingPageUrl}®istrationFlowType={registrationFlowType}', | |||
| @@ -1,12 +1,12 @@ | |||
| import axios from 'axios'; | |||
| import axios from "axios"; | |||
| // import queryString from 'qs'; | |||
| const request = axios.create({ | |||
| baseURL: process.env.REACT_APP_BASE_API_URL, | |||
| baseURL: "http://localhost:1337/", | |||
| headers: { | |||
| 'Content-Type': 'application/json', | |||
| "Content-Type": "application/json", | |||
| }, | |||
| // withCredentials: true, | |||
| withCredentials: true, | |||
| // paramsSerializer: (params) => | |||
| // queryString.stringify(params, { arrayFormat: 'comma' }), | |||
| }); | |||
| @@ -27,7 +27,7 @@ export const deleteRequest = (url, params = null, options = null) => | |||
| request.delete(url, { params, ...options }); | |||
| export const downloadRequest = (url, params = null, options = null) => | |||
| request.get(url, { params, ...options, responseType: 'blob' }); | |||
| request.get(url, { params, ...options, responseType: "blob" }); | |||
| export const replaceInUrl = (url, pathVariables = {}) => { | |||
| const keys = Object.keys(pathVariables); | |||
| @@ -37,7 +37,7 @@ export const replaceInUrl = (url, pathVariables = {}) => { | |||
| return keys.reduce( | |||
| (acc, key) => acc.replace(`{${key}}`, pathVariables[`${key}`]), | |||
| url, | |||
| url | |||
| ); | |||
| }; | |||
| @@ -15,8 +15,8 @@ export const updateSecurityAnswer = (payload) => | |||
| export const refreshTokenRequest = (payload) => | |||
| postRequest(apiEndpoints.authentications.refreshToken, payload); | |||
| export const logoutUserRequest = (payload) => | |||
| postRequest(apiEndpoints.users.logout, payload); | |||
| export const logoutUserRequest = () => | |||
| getRequest(apiEndpoints.users.logout); | |||
| export const generateTokenRequest = (payload) => | |||
| postRequest(apiEndpoints.authentications.generateToken, payload); | |||
| @@ -2,10 +2,10 @@ import axios from "axios"; | |||
| import jwt from "jsonwebtoken"; | |||
| import { JWT_REFRESH_TOKEN, JWT_TOKEN } from "../../constants/localStorage"; | |||
| import { attachBeforeRequestListener } from "../../request/index"; | |||
| import { | |||
| authScopeStringGetHelper, | |||
| } from "../../util/helpers/authScopeHelpers"; | |||
| import { authScopeStringGetHelper } from "../../util/helpers/authScopeHelpers"; | |||
| import { logoutUser, refreshUserToken } from "../actions/login/loginActions"; | |||
| import { apiDefaultUrl } from "../../request/index"; | |||
| import apiEndpoints from "../../request/apiEndpoints"; | |||
| export const accessTokensMiddlewareInterceptorName = "ACCESS_TOKEN_INTERCEPTOR"; | |||
| @@ -31,12 +31,16 @@ export default ({ dispatch }) => | |||
| // If access token is expired, refresh access token | |||
| if (new Date() > new Date(jwtTokenDecoded.exp * 1000)) { | |||
| const axiosResponse = await axios.post( | |||
| `${process.env.REACT_APP_BASE_API_URL}auth/refresh`, | |||
| `${apiDefaultUrl}${apiEndpoints.authentications.refreshToken}`, | |||
| { | |||
| token: refresh, | |||
| refreshToken: refresh, | |||
| }, | |||
| { | |||
| withCredentials: true, | |||
| headers: { Authorization: `Bearer ${jwtToken}` }, | |||
| } | |||
| ); | |||
| const newToken = axiosResponse.data.newAccessToken; | |||
| const newToken = axiosResponse.data.jwt; | |||
| response.headers.Authorization = `Bearer ${newToken}`; | |||
| @@ -38,8 +38,8 @@ function setUser(state, action) { | |||
| ...state, | |||
| token: { | |||
| ...state.token, | |||
| JwtToken: action.payload.token, | |||
| JwtRefreshToken: action.payload.refresh | |||
| JwtToken: action.payload.jwt, | |||
| JwtRefreshToken: action.payload.refreshToken | |||
| }, | |||
| }; | |||
| } | |||
| @@ -33,11 +33,11 @@ import { rejectErrorCodeHelper } from "../../util/helpers/rejectErrorCodeHelper" | |||
| function* fetchUser({ payload }) { | |||
| try { | |||
| const { data } = yield call(attemptLogin, payload); | |||
| if (data?.token) { | |||
| const user = jwt.decode(data.token); | |||
| yield call(authScopeSetHelper, JWT_TOKEN, data.token); | |||
| yield call(authScopeSetHelper, JWT_REFRESH_TOKEN, data.refresh); | |||
| yield call(addHeaderToken, data.token); | |||
| if (data?.jwt) { | |||
| const user = data?.user; | |||
| yield call(authScopeSetHelper, JWT_TOKEN, data.jwt); | |||
| yield call(authScopeSetHelper, JWT_REFRESH_TOKEN, data?.refreshToken); | |||
| yield call(addHeaderToken, data?.jwt); | |||
| yield put(setUser(user)); | |||
| } | |||
| yield put(fetchUserSuccess(data)); | |||
| @@ -78,8 +78,7 @@ function* logoutUser() { | |||
| const token = yield call(authScopeStringGetHelper, JWT_REFRESH_TOKEN); | |||
| const user = yield call(jwt.decode, token); | |||
| if (user) { | |||
| let requestData = { token }; | |||
| yield call(logoutUserRequest, requestData); | |||
| yield call(logoutUserRequest); | |||
| } | |||
| } catch (error) { | |||
| console.log(error); // eslint-disable-line | |||