fix: Not setting the auth state in Application
This commit is contained in:
@@ -22,6 +22,7 @@ import { ILearner } from "../models/learner";
|
||||
import { IVocab, VocabType } from "../models/vocab";
|
||||
import { IReviewMetadata, ReviewType } from "../models/review";
|
||||
import { IUser } from "../models/user";
|
||||
import { IResponse } from "../models/server";
|
||||
|
||||
interface IProps {
|
||||
authenticated: boolean;
|
||||
@@ -195,7 +196,7 @@ export default class Application extends React.Component<IProps> {
|
||||
});
|
||||
}
|
||||
|
||||
login = (username: string, password: string): Promise<IUser | {}> => {
|
||||
login = (username: string, password: string): Promise<IUser | IResponse> => {
|
||||
return new Promise((res, rej) => {
|
||||
fetch(`${BACKEND_URL}/login`, {
|
||||
method: "POST",
|
||||
@@ -209,15 +210,16 @@ export default class Application extends React.Component<IProps> {
|
||||
password,
|
||||
}),
|
||||
}).then(data => data.json())
|
||||
.then(resp => {
|
||||
.then((resp: IResponse) => {
|
||||
if (resp.error === "0") {
|
||||
// Successful login
|
||||
this.props.setUser(resp.data);
|
||||
setSessionToken(window, resp.data.sessionToken);
|
||||
this.props.setAuthenticated(true);
|
||||
|
||||
res(resp.data);
|
||||
} else {
|
||||
rej({});
|
||||
rej(resp);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user