Fixed auth token header, Moved dispatch out of constructors
This commit is contained in:
parent
44c6117ce1
commit
ffe3cba510
|
@ -10,17 +10,19 @@ const localStorage = global.process && process.env.NODE_ENV === "test"
|
||||||
|
|
||||||
function headers() {
|
function headers() {
|
||||||
const token = localStorage.getItem("userToken") || "";
|
const token = localStorage.getItem("userToken") || "";
|
||||||
|
let header = {
|
||||||
return {
|
|
||||||
Accept: "application/json",
|
Accept: "application/json",
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json"
|
||||||
Authorization: `Token ${token}`
|
|
||||||
};
|
};
|
||||||
|
if (token) {
|
||||||
|
header["Authorization"] = `Token ${token}`;
|
||||||
|
}
|
||||||
|
return header;
|
||||||
}
|
}
|
||||||
|
|
||||||
const apiInstance = axios.create({
|
const apiInstance = axios.create({
|
||||||
baseURL: API_ENDPOINT,
|
baseURL: API_ENDPOINT,
|
||||||
timeout: 3000,
|
timeout: 3000
|
||||||
});
|
});
|
||||||
|
|
||||||
export function get(url, params = {}) {
|
export function get(url, params = {}) {
|
||||||
|
|
|
@ -13,8 +13,7 @@ import { sendLoginRequest } from "../../actions/auth/saga.actions";
|
||||||
import Error from "../Shared/Error";
|
import Error from "../Shared/Error";
|
||||||
|
|
||||||
class Login extends Component {
|
class Login extends Component {
|
||||||
constructor(props) {
|
componentWillMount() {
|
||||||
super(props);
|
|
||||||
this.props.dispatch(clearAuthRequestError());
|
this.props.dispatch(clearAuthRequestError());
|
||||||
this.props.dispatch(clearAuthRequestSuccess());
|
this.props.dispatch(clearAuthRequestSuccess());
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,8 +14,7 @@ import { sendRegisterRequest } from "../../actions/auth/saga.actions";
|
||||||
import Error from "../Shared/Error";
|
import Error from "../Shared/Error";
|
||||||
|
|
||||||
class Register extends Component {
|
class Register extends Component {
|
||||||
constructor(props) {
|
componentWillMount() {
|
||||||
super(props);
|
|
||||||
this.props.dispatch(clearAuthRequestError());
|
this.props.dispatch(clearAuthRequestError());
|
||||||
this.props.dispatch(clearAuthRequestSuccess());
|
this.props.dispatch(clearAuthRequestSuccess());
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,8 +13,7 @@ import { sendChangePasswordRequest } from "../../actions/auth/saga.actions";
|
||||||
import Error from "../Shared/Error";
|
import Error from "../Shared/Error";
|
||||||
|
|
||||||
class Settings extends Component {
|
class Settings extends Component {
|
||||||
constructor(props) {
|
componentWillMount() {
|
||||||
super(props);
|
|
||||||
this.props.dispatch(clearAuthRequestError());
|
this.props.dispatch(clearAuthRequestError());
|
||||||
this.props.dispatch(clearAuthRequestSuccess());
|
this.props.dispatch(clearAuthRequestSuccess());
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,8 +12,7 @@ import { sendEmailVerificationRequest } from "../../actions/auth/saga.actions";
|
||||||
import Error from "../Shared/Error";
|
import Error from "../Shared/Error";
|
||||||
|
|
||||||
class VerifyEmail extends Component {
|
class VerifyEmail extends Component {
|
||||||
constructor(props) {
|
componentWillMount() {
|
||||||
super(props);
|
|
||||||
const emailKey = this.props.match.params.emailKey;
|
const emailKey = this.props.match.params.emailKey;
|
||||||
this.props.dispatch(clearEmailVerificationError());
|
this.props.dispatch(clearEmailVerificationError());
|
||||||
this.props.dispatch(clearEmailVerificationSuccess());
|
this.props.dispatch(clearEmailVerificationSuccess());
|
||||||
|
|
Loading…
Reference in New Issue
Block a user