0

can anyone tell my why this happens?

checkSessionToken() {
    var sessionToken = loginCookies.get("sessionToken");

    if (typeof sessionToken !== "undefined") {
        var callback = "a";
        axios
            .get(backendServerURL + "/login.php", {
                params: {
                    action: "checkSessionToken",
                    token: sessionToken
                }
            })
            .then(res => {
                callback = "b";
                console.log("---");
            });
        return callback;
    } else {
        return false;
    }
}

render() {
    console.log(this.checkSessionToken());
}

the function is always returning "a" ... but I see the "---" in the console so it should be "b" does anyone of you know why this happens .... sorry for might beeing a noob I'm new to js

EDIT: when I say

return "b";

in the

.then(res => {});

so it would be

.then(res => {
    return "b";
});

it returns undefined

Gianluca Filitz
  • 371
  • 1
  • 2
  • 10

0 Answers0