third-login.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import AsyncTask from './asyncTask'
  2. const gTask = new AsyncTask()
  3. /* window.fbAsyncInit = () => {
  4. FB.init({
  5. appId: '683963442752208',
  6. cookie: true, // Enable cookies to allow the server to access the session.
  7. version: 'v13.0',
  8. })
  9. } */
  10. function fbStatusChangeCallback(response: any) {
  11. // Called with the results from FB.getLoginStatus().
  12. console.log('statusChangeCallback')
  13. console.log(response) // The current login status of the person.
  14. if (response.status === 'connected') {
  15. // Logged into your webpage and Facebook.
  16. fbConnect()
  17. }
  18. }
  19. function fbConnect() {
  20. // Testing Graph API after login. See statusChangeCallback() for when this call is made.
  21. FB.api('/me?fields=id,name,email', function (response: any) {
  22. console.log(response)
  23. location.href =
  24. '/api/user/facebook/callback?name=' +
  25. response.name +
  26. '&email=' +
  27. response.email
  28. })
  29. }
  30. export function FBLogin() {
  31. FB.login(fbStatusChangeCallback, { scope: 'public_profile,email' })
  32. }
  33. export function AppleLogin() {
  34. location.href = '/api/user/apple/login'
  35. }
  36. export async function renderGoogleLoginButton(parent: HTMLElement) {
  37. await gTask.promise
  38. google.accounts.id.renderButton(parent, {
  39. type: 'icon',
  40. shape: 'circle',
  41. theme: 'filled_black',
  42. width: 40,
  43. })
  44. }
  45. window.addEventListener('load', () => {
  46. google.accounts.id.initialize({
  47. client_id:
  48. '393349837160-3opoqoo9l0gk9uimu212gp9uvm72406m.apps.googleusercontent.com',
  49. login_uri: import.meta.env.VITE_ORIGIN + '/api/user/google/callback',
  50. ux_mode: 'redirect',
  51. })
  52. gTask.done()
  53. })