4

Giving Svelte/Sapper a look and am curious what the right way to add something like Google Sign-In for Websites to my app.

I have everything working from the example code they give you from the site above, but I've done it by adding the onsuccess "onSignIn" function to the template.html file which doesn't seem like the right way to do this.

Inside src/routes/template.html

<script src="https://apis.google.com/js/platform.js" async defer></script>
<script>
  function onSignIn(googleUser) {
    var profile = googleUser.getBasicProfile();
    console.log("ID: " + profile.getId());
  }
</script>

Inside src/components/Nav.svelte

<div class="g-signin2" data-onsuccess="onSignIn" data-theme="dark"></div>

The code above works fine because onSignIn has access to window, but it seems like I should be able to add this to the Nav component where the button itself lives. Is there a preferred way to handle something like this?

randyjensen
  • 127
  • 2
  • 10
  • [This](https://dev.to/ajonp/rxfire-in-svelte-3-using-firebase-firestore-and-authentication-pca) article may help you! – Shaya Ulman Jul 08 '19 at 17:07
  • 1
    The founder, Rich Harris, has pointed out window element for reaching global variables: Please see [here](https://stackoverflow.com/questions/57954008/call-svelte-components-function-from-global-scope) – Bitfinicon Feb 25 '22 at 09:50

1 Answers1

5

If anyone is looking for something similar, I found this git repo that I was able to get started and modify to suit my needs github.com/beyonk-adventures/svelte-social-auth.

randyjensen
  • 127
  • 2
  • 10