diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2018-09-17 12:40:40 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2018-09-17 12:40:40 +0200 |
| commit | 15e5df27774fef8d976c74b6ec7bcf8f878e5834 (patch) | |
| tree | b9d0110849789382bf9f255fcadf4587e338d2f1 /app/client/auth | |
| parent | 439888003a41279a0fe5a74ac5b92898cabd827b (diff) | |
log in / log out
Diffstat (limited to 'app/client/auth')
| -rw-r--r-- | app/client/auth/auth.actions.js | 27 | ||||
| -rw-r--r-- | app/client/auth/login.component.js | 2 |
2 files changed, 24 insertions, 5 deletions
diff --git a/app/client/auth/auth.actions.js b/app/client/auth/auth.actions.js index c075646..aa46d1b 100644 --- a/app/client/auth/auth.actions.js +++ b/app/client/auth/auth.actions.js @@ -1,5 +1,5 @@ import types from '../types' -import { put } from '../api/crud.fetch' +import { put, _get_headers } from '../api/crud.fetch' export const setToken = (data) => { return { type: types.auth.set_token, data } @@ -13,7 +13,7 @@ export const setError = (data) => { export const setCurrentUser = (data) => { return { type: types.auth.set_current_user, data } } -export function logout() { +export const clearCurrentUser = () => { return { type: types.auth.logout_user } } export function initialized() { @@ -45,6 +45,7 @@ export function login(username, password) { .then(req => req.json()) .then(data => { console.log(data) + console.log('logged in', data.user.username) dispatch(setCurrentUser(data.user)) }) .catch(error => { @@ -61,6 +62,7 @@ export function signup(data) { .then(req => req.json()) .then(data => { console.log(data) + console.log('signed up', data.user.username) dispatch(setCurrentUser(data.user)) }) .catch(error => { @@ -76,7 +78,8 @@ export function checkin() { fetch(api.checkin, put({})) .then(req => req.json()) .then(data => { - console.log(data) + // console.log(data) + console.log('checked in', data.user.username) dispatch(setCurrentUser(data.user)) }) .catch(error => { @@ -85,3 +88,21 @@ export function checkin() { }) } } + +export function logout() { + return (dispatch) => { + dispatch(loading()) + fetch(api.logout, _get_headers({})) + .then(req => req.json()) + .then(data => { + console.log('logged out', data) + dispatch(clearCurrentUser()) + dispatch(initialized()) + }) + .catch(error => { + console.error('err', error) + dispatch(clearCurrentUser()) + dispatch(initialized()) + }) + } +} diff --git a/app/client/auth/login.component.js b/app/client/auth/login.component.js index 723d68a..2ef01a6 100644 --- a/app/client/auth/login.component.js +++ b/app/client/auth/login.component.js @@ -15,7 +15,6 @@ class Login extends Component { } constructor() { super() - console.log('yooooooo') this.handleChange = this.handleChange.bind(this) this.handleSubmit = this.handleSubmit.bind(this) } @@ -31,7 +30,6 @@ class Login extends Component { this.props.actions.login(this.state.username, this.state.password) } render(){ - console.log('yooooooo') if (this.props.auth.isAuthenticated) { let { returnTo } = this.props.auth if (!returnTo || returnTo.match(/(login|logout|signup)/i)) { |
