Created
January 10, 2016 17:49
-
-
Save dpastoor/7af22aada21119dc1b08 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { domain } from 'config' | |
| export default { | |
| signup: async function (body, cb) { | |
| let response = await fetch(`${domain}:8080/signup`, { | |
| method: `POST`, | |
| headers: { | |
| 'Content-Type': `application/json` | |
| }, | |
| body: JSON.stringify(body) | |
| }) | |
| let { success, message } = await response.json() | |
| if (success) this.login(body, cb) | |
| else cb({ success, message }) | |
| }, | |
| login: async function (body, cb) { | |
| let response = await fetch(`${domain}:8080/api/authenticate`, { | |
| method: `POST`, | |
| headers: { 'Content-Type': `application/json` }, | |
| body: JSON.stringify(body) | |
| }) | |
| let { success, message, token, user } = await response.json() | |
| if (success) { | |
| localStorage.token = token | |
| localStorage.userId = user._id | |
| localStorage.userEmail = user.email | |
| cb({ success, message, user }) | |
| } | |
| else { | |
| cb({ message }) | |
| } | |
| }, | |
| logout (cb) { | |
| delete localStorage.token | |
| if (cb) cb() | |
| }, | |
| loggedIn() { | |
| return !!localStorage.token | |
| }, | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment