mirror of https://github.com/status-im/fathom.git
get auth state from cookie upon render
This commit is contained in:
parent
86cbfa8dd4
commit
fbd591547c
|
@ -33,20 +33,34 @@ const Login = {
|
|||
view(c) {
|
||||
return m('div.block', [
|
||||
m('h2', 'Login'),
|
||||
m('p', 'Please enter your credentials to login to your Ana dashboard.'),
|
||||
m('form', {
|
||||
method: "POST",
|
||||
onsubmit: c.onSubmit
|
||||
}, [
|
||||
m('div.form-group', [
|
||||
m('label', 'Email address'),
|
||||
m('input', { type: "email", onchange: m.withAttr("value", c.data.email ) }),
|
||||
m('input', {
|
||||
type: "email",
|
||||
name: "email",
|
||||
required: true,
|
||||
onchange: m.withAttr("value", c.data.email )
|
||||
}),
|
||||
]),
|
||||
m('div.form-group', [
|
||||
m('label', 'Password'),
|
||||
m('input', { type: "password", onchange: m.withAttr("value", c.data.password ) }),
|
||||
m('input', {
|
||||
type: "password",
|
||||
name: "password",
|
||||
required: true,
|
||||
onchange: m.withAttr("value", c.data.password )
|
||||
}),
|
||||
]),
|
||||
m('div.form-group', [
|
||||
m('input', { type: "submit", value: "Sign in" }),
|
||||
m('input', {
|
||||
type: "submit",
|
||||
value: "Sign in"
|
||||
}),
|
||||
]),
|
||||
])
|
||||
])
|
||||
|
|
|
@ -10,7 +10,7 @@ import LogoutButton from './components/logoutButton.js';
|
|||
const App = {
|
||||
controller(args) {
|
||||
this.state = {
|
||||
authenticated: false
|
||||
authenticated: document.cookie.indexOf('auth') > -1
|
||||
};
|
||||
|
||||
this.setState = function(nextState) {
|
||||
|
@ -23,11 +23,13 @@ const App = {
|
|||
},
|
||||
view(c) {
|
||||
if( ! c.state.authenticated ) {
|
||||
return m.component(Login, {
|
||||
return m('div.container', [
|
||||
m.component(Login, {
|
||||
onAuth: () => {
|
||||
c.setState({ authenticated: true })
|
||||
}
|
||||
});
|
||||
})
|
||||
]);
|
||||
}
|
||||
|
||||
return [
|
||||
|
|
Loading…
Reference in New Issue