summaryrefslogtreecommitdiff
path: root/animism-align/frontend/app/views/auth/auth.actions.js
diff options
context:
space:
mode:
Diffstat (limited to 'animism-align/frontend/app/views/auth/auth.actions.js')
-rw-r--r--animism-align/frontend/app/views/auth/auth.actions.js33
1 files changed, 33 insertions, 0 deletions
diff --git a/animism-align/frontend/app/views/auth/auth.actions.js b/animism-align/frontend/app/views/auth/auth.actions.js
new file mode 100644
index 0000000..d7663b7
--- /dev/null
+++ b/animism-align/frontend/app/views/auth/auth.actions.js
@@ -0,0 +1,33 @@
+import fetch from 'node-fetch'
+
+import { session } from 'app/session'
+
+const urls = {
+ login: "/api/v1/auth/login",
+}
+
+export const login = (data) => dispatch => (
+ fetch(urls.login, {
+ method: 'POST',
+ body: JSON.stringify(data),
+ credentials: 'same-origin',
+ headers: {
+ 'Accept': 'application/json',
+ 'Content-Type': 'application/json'
+ }
+ })
+ .then(req => req.json())
+ .then(res => {
+ if (res.access_token) {
+ session.set('access_token', res.access_token)
+ }
+ return res
+ })
+ .catch(error => {
+ console.error(error)
+ })
+)
+
+export const logout = () => dispatch => {
+ session.set('access_token', '')
+}