From d0a251f69a7e2e2685a80c73670496fe9abca4af Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Mon, 25 Nov 2019 23:25:08 +0100 Subject: [PATCH] Moved register and login requests to api.js. --- src/api.js | 39 ++++++++++++++++++++++++++++++++ src/components/Register.vue | 29 +++++++++++------------- src/components/Signin.vue | 44 +++++++++++++++++-------------------- 3 files changed, 72 insertions(+), 40 deletions(-) diff --git a/src/api.js b/src/api.js index dd2f38c..8668aac 100644 --- a/src/api.js +++ b/src/api.js @@ -211,6 +211,43 @@ const getRequestStatus = (id, type, authorization_token=undefined) => { .catch(err => Promise.reject(err)) } +// - - - Seasoned user endpoints - - - + +const register = (username, password) => { + const url = new URL('v1/user', SEASONED_URL) + const options = { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ username, password }) + } + + return fetch(url.href, options) + .then(resp => resp.json()) + .catch(error => { + console.error('Unexpected error occured before receiving response. Error:', error) + // TODO log to sentry the issue here + throw error + }) +} + +const login = (username, password) => { + const url = new URL('v1/user/login', SEASONED_URL) + const options = { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ username, password }) + } + + return fetch(url.href, options) + .then(resp => checkStatus) + .then(resp => resp.json()) + .catch(error => { + console.error('Unexpected error occured before receiving response. Error:', error) + // TODO log to sentry the issue here + throw error + }) +} + // - - - Authenticate with plex - - - const plexAuthenticate = (username, password) => { @@ -303,6 +340,8 @@ export { request, getRequestStatus, plexAuthenticate, + register, + login, getEmoji, elasticSearchMoviesAndShows } diff --git a/src/components/Register.vue b/src/components/Register.vue index 5d94ff1..38d5c43 100644 --- a/src/components/Register.vue +++ b/src/components/Register.vue @@ -18,7 +18,7 @@