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) {
|
view(c) {
|
||||||
return m('div.block', [
|
return m('div.block', [
|
||||||
m('h2', 'Login'),
|
m('h2', 'Login'),
|
||||||
|
m('p', 'Please enter your credentials to login to your Ana dashboard.'),
|
||||||
m('form', {
|
m('form', {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
onsubmit: c.onSubmit
|
onsubmit: c.onSubmit
|
||||||
}, [
|
}, [
|
||||||
m('div.form-group', [
|
m('div.form-group', [
|
||||||
m('label', 'Email address'),
|
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('div.form-group', [
|
||||||
m('label', 'Password'),
|
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('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 = {
|
const App = {
|
||||||
controller(args) {
|
controller(args) {
|
||||||
this.state = {
|
this.state = {
|
||||||
authenticated: false
|
authenticated: document.cookie.indexOf('auth') > -1
|
||||||
};
|
};
|
||||||
|
|
||||||
this.setState = function(nextState) {
|
this.setState = function(nextState) {
|
||||||
|
@ -23,11 +23,13 @@ const App = {
|
||||||
},
|
},
|
||||||
view(c) {
|
view(c) {
|
||||||
if( ! c.state.authenticated ) {
|
if( ! c.state.authenticated ) {
|
||||||
return m.component(Login, {
|
return m('div.container', [
|
||||||
|
m.component(Login, {
|
||||||
onAuth: () => {
|
onAuth: () => {
|
||||||
c.setState({ authenticated: true })
|
c.setState({ authenticated: true })
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
|
Loading…
Reference in New Issue