-
-
Save Struchu/9c175272591df399fc55e9502addbec5 to your computer and use it in GitHub Desktop.
Reactive Coordinators proof of concept
This file contains 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 axios from 'axios'; | |
import { defer } from 'rxjs'; | |
import { pluck } from 'rxjs/operators'; | |
const connector = axios.create({ | |
/* Initialize axios for out API */ | |
}); | |
// Takes user data and sends registration request. | |
// Returns observable that emits JWT token when registration is successful. | |
export function register({ | |
email, password1, password2, | |
firstName, lastName, | |
}) { | |
return defer(() => connector.post( | |
'/register/', | |
{ | |
email, password1, password2, | |
first_name: firstName, | |
last_name: lastName, | |
privacy_accepted: true, | |
} | |
)).pipe( | |
pluck('data', 'token'), | |
); | |
} | |
// Takes user credentials and sends login request. | |
// Returns observable that emits an JWT token when login attempt is successful. | |
export function login({ email, password }) { | |
return defer(() => ( | |
connector.post('/rest-auth/login/', { email, password }) | |
)).pipe( | |
pluck('data', 'token'), | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment