'NameError? Its says chBracketBal2 is not defined
I want to know what is wrong with my code, I tried running it it says NameError. I already defined chBracketBal2 on line two. Can someone please help me Im really confused?
from stack import LinkedStack
def chBracketBal2 (exp, begList, endList):
stk = LinkedStack()
for ch in exp:
if ch in begList:
stk.push(ch)
elif ch in endList:
if stk.isEmpty():
return False
chFromStack = stk.pop()
for i in range (len(begList)):
if ch == begList [i] and chFromStack != endList [i]:
return False
return stk.isEmpty()
string = "[]{}"
begList = ["[","{","("]
endList = ["]","}",")"]
print (chBracketsBal2(exp, begList, endList))
Solution 1:[1]
If you are going to use JWT, then you can use local storage to persist if the user is authenticated or not.
For example: after performing an api call
const handleSubmit = async e => {
e.preventDefault();
const user = { username, password };
// send the username and password to the server
const response = await axios.post(
"http://your-api/api/login",
user
);
// set the state of the user
setUser(response.data)
// store the user in localStorage
localStorage.setItem('user', response.data)
console.log(response.data)
};
And you can get the user like this:
useEffect(() => {
const loggedInUser = localStorage.getItem("user");
if (loggedInUser) {
const foundUser = JSON.parse(loggedInUser);
setUser(foundUser);
}
}, []);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Daniel |
