summaryrefslogtreecommitdiff
path: root/app/client/auth/auth.actions.js
diff options
context:
space:
mode:
Diffstat (limited to 'app/client/auth/auth.actions.js')
-rw-r--r--app/client/auth/auth.actions.js27
1 files changed, 24 insertions, 3 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())
+ })
+ }
+}