mirror of
https://github.com/openziti/zrok.git
synced 2024-11-28 19:14:07 +01:00
store login details in localStorage (#17)
This commit is contained in:
parent
e699994ca5
commit
34a54ead88
@ -2,7 +2,7 @@ import Login from './Login';
|
||||
import Logout from './Logout';
|
||||
import Version from './Version';
|
||||
import * as gateway from "./api/gateway";
|
||||
import {useState} from "react";
|
||||
import {useEffect, useState} from "react";
|
||||
|
||||
gateway.init({
|
||||
url: '/api/v1'
|
||||
@ -11,6 +11,14 @@ gateway.init({
|
||||
const App = () => {
|
||||
const [user, setUser] = useState();
|
||||
|
||||
useEffect(() => {
|
||||
const localUser = localStorage.getItem("user")
|
||||
if(localUser) {
|
||||
setUser(JSON.parse(localUser))
|
||||
console.log('reloaded user', localUser)
|
||||
}
|
||||
}, []);
|
||||
|
||||
if (!user) {
|
||||
return (
|
||||
<Login
|
||||
|
@ -7,13 +7,17 @@ const Login = (props) => {
|
||||
|
||||
const handleSubmit = async e => {
|
||||
e.preventDefault()
|
||||
|
||||
identity.login({body: {"email": email, "password": password}})
|
||||
.then(resp => {
|
||||
if(!resp.error) {
|
||||
props.loginSuccess({
|
||||
email: email,
|
||||
token: resp.token
|
||||
})
|
||||
let user = {
|
||||
"email": email,
|
||||
"token": resp.data
|
||||
}
|
||||
props.loginSuccess(user)
|
||||
localStorage.setItem('user', JSON.stringify(user))
|
||||
console.log(user)
|
||||
console.log('login succeeded', resp)
|
||||
} else {
|
||||
console.log('login failed')
|
||||
|
Loading…
Reference in New Issue
Block a user