utils.js 527 B

1234567891011121314151617181920
  1. import { API, showError } from '../helpers';
  2. export async function getOAuthState() {
  3. const res = await API.get('/api/oauth/state');
  4. const { success, message, data } = res.data;
  5. if (success) {
  6. return data;
  7. } else {
  8. showError(message);
  9. return '';
  10. }
  11. }
  12. export async function onGitHubOAuthClicked(github_client_id) {
  13. const state = await getOAuthState();
  14. if (!state) return;
  15. window.open(
  16. `https://github.com/login/oauth/authorize?client_id=${github_client_id}&state=${state}&scope=user:email`
  17. );
  18. }