From 0907418ce2c6ca498b02e8e514e4945d79750467 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Fri, 5 Mar 2021 19:10:55 +0100 Subject: adding login view --- .../frontend/app/views/auth/auth.actions.js | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 animism-align/frontend/app/views/auth/auth.actions.js (limited to 'animism-align/frontend/app/views/auth/auth.actions.js') 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', '') +} -- cgit v1.2.3-70-g09d2