Skip to content

Instantly share code, notes, and snippets.

@Struchu

Struchu/api.js Secret

Created June 6, 2019 18:20
Show Gist options
  • Save Struchu/9c175272591df399fc55e9502addbec5 to your computer and use it in GitHub Desktop.
Save Struchu/9c175272591df399fc55e9502addbec5 to your computer and use it in GitHub Desktop.
Reactive Coordinators proof of concept
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