-
Notifications
You must be signed in to change notification settings - Fork 219
Bugs fix #658
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bugs fix #658
Changes from all commits
f962081
e4511e1
8becc49
b422a86
05d46cb
47108d9
d0b67e6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,15 +4,17 @@ import "./App.css"; | |
import { Provider } from "react-redux"; | ||
import store from "./store"; | ||
import jwt_decode from "jwt-decode"; | ||
import { setAuthToken } from "./utils/setAuthToken"; | ||
import { allowCredentialsInHeader } from "./utils/allowCredentialsInHeader"; | ||
import { setCurrentUser, logoutUser } from "./actions/authAction"; | ||
import "./css/main.scss"; | ||
import ReactGA from "react-ga"; | ||
|
||
allowCredentialsInHeader() | ||
|
||
function App() { | ||
useEffect(() => { | ||
ReactGA.initialize("UA-173245995-1"); | ||
setAuthToken() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This might effect Analytics part cc @AuraOfDivinity There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was already there! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should I make it work as componentDidMount? |
||
|
||
}); | ||
return ( | ||
<Provider store={store}> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ import axios from 'axios' | |
import { errorHandler } from '../utils/errorHandler' | ||
import { setRequestStatus } from '../utils/setRequestStatus' | ||
import { SET_ADMIN, GET_ADMIN } from './types' | ||
import { setAuthToken } from '../utils/setAuthToken' | ||
import jwt_decode from 'jwt-decode'; | ||
import { setCurrentUser } from './authAction' | ||
import { BASE_URL } from './baseApi' | ||
|
@@ -27,31 +26,27 @@ export const createAdmin = (adminInfo) => async (dispatch) => { | |
export const loginAdmin = (adminInfo, history) => async (dispatch) => { | ||
try { | ||
const res = await axios.post(`${BASE_URL}/auth/login/`, adminInfo) | ||
dispatch(setRequestStatus(false)); | ||
if (res.status === 200) { | ||
dispatch(setRequestStatus(false)); | ||
if (res.status === 200) { | ||
dispatch(setRequestStatus(true)); | ||
|
||
const token = res.data.token; | ||
dispatch(setRequestStatus(true)); | ||
// update state with user | ||
localStorage.setItem('userId', res.data.user) | ||
dispatch(setCurrentUser(res.data.user._id)); | ||
|
||
localStorage.setItem("jwtToken", (token)); | ||
setAuthToken(token); | ||
// update localStorage with admin status | ||
localStorage.setItem('username', `${res.data.user.name.firstName} ${res.data.user.name.lastName}`) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Local storage is not that secure!! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Setting names in local storage won't do any harm as the protected resources sent from the server need that token in cookie. |
||
localStorage.setItem('admin', res.data.user.isAdmin) | ||
localStorage.setItem('ticketModerator', res.data.user.isTicketsModerator) | ||
localStorage.setItem('orgId', res.data.user.orgId); | ||
|
||
// update state with user | ||
const decodedData = await jwt_decode(token); | ||
localStorage.setItem('userId', decodedData._id) | ||
dispatch(setCurrentUser(decodedData)); | ||
|
||
// update localStorage with admin status | ||
localStorage.setItem('admin', true) | ||
|
||
dispatch({ | ||
type: SET_ADMIN, | ||
payload: true | ||
}) | ||
|
||
history.push("/dashboard"); | ||
dispatch({ | ||
type: SET_ADMIN, | ||
payload: res.data.user.isAdmin | ||
}) | ||
history.push("/dashboard"); | ||
} | ||
} catch (error) { | ||
dispatch(errorHandler(error)) | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import axios from "axios"; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @lazycipher now you are not using authorization header ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes after shifting the auth method to use cookies, we're using auth in the cookie header. |
||
export const allowCredentialsInHeader = () => { | ||
axios.defaults.withCredentials = true; | ||
} |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if authorization is not required in header, remove the function too instead of just removing from here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not understand.