Giter Club home page Giter Club logo

svelte-social-auth's Introduction





Svelte Social Auth

js-standard-style svelte-v3 publish

Google and Facebook Auth

SvelteKit SSR Ready Svelte v3

installation

npm i @beyonk/svelte-social-auth --save-dev

Usage

<GoogleAuth clientId="your-google-auth-client-id" on:auth-success={e => console.dir(e.detail.user)} />
<FacebookAuth appId="your-facebook-app-id" on:auth-success={e => console.dir(e.detail.user)} />

<script>
  import { GoogleAuth, FacebookAuth } from '@beyonk/svelte-social-auth'
</script>

Customising the buttons

Buttons have default graphics and text, however, both buttons are slotted, so simply put the button content you want inside:

<GoogleAuth>
  <div>my custom content</div>
</GoogleAuth>

Attributes

Common attributes:

Attribute Description Type Default
text Text of the sign-in button string 'Sign in with '

The attributes for the GoogleAuth component are:

Attribute Description Type Default
clientId Google service account client id string -

The attributes for the FacebookAuth component are:

Attribute Description Type Default
appId Facebook app id string -

Events

The events fired by the GoogleAuth component are:

Event Purpose Properties
on:auth-success User authentication success { user }
on:auth-failure User authentication failure { error }
on:init-error Google Auth initialisation failure { error }

The events fired by the FacebookAuth component are:

Event Purpose Properties
on:auth-success User authentication success { user }
on:auth-failure User authentication failure { error }

Developing / Contributing

Note that Facebook requires that you have HTTPS locally, despite their documentation to the contrary, so you will need to generate some SSL certs and point rollup config at them.

Put your app and client ids in an .env file

.env.local
VITE_GOOGLE_CLIENT_ID=<your-google-client-id>
VITE_FACEBOOK_APP_ID=<your-facebook-app-id>
``

```bash
pnpm dev

svelte-social-auth's People

Contributors

ahpercival avatar andykillen avatar antony avatar benthompsoncode avatar dependabot[bot] avatar sandipnirmal avatar thiagoarmede avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

svelte-social-auth's Issues

Typescript Support

Woudl be nice if you could provide a typefile so i can use this in a svelte ts project.

Is it possible to make this work with sapper?

Hi there,

thanks for the great extension. Just wondering if is possible to make this work with sapper.

I'm getting the following error:

<FacebookAuth> is not a valid SSR component. You may need to review your build config to ensure that dependencies are compiled, rather than imported as pre-compiled modules

install instructions needed in readme.

using
npm i @beyonk/svelte-social-auth
works
but
npm i beyonk-adventures/svelte-social-auth
does not work, even though it installs. it complains
Error: Cannot find module 'node_modules/@beyonk/svelte-social-auth/index.js'.

I hereby suggest you add the install instructions to the readme.md

gauth initialisation error

I'm getting this error on page load :

{
details: 
"You have created a new client application that uses libraries for user authentication or authorization that will soon be deprecated. New clients must use the new libraries instead; existing clients must also migrate before these libraries are deprecated. See the [Migration Guide](https://developers.google.com/identity/gsi/web/guides/gis-migration) for more information."
error: "idpiframe_initialization_failed"
}

any tips on how to fix it?

thank you

Support more options for Google Auth

Google Auth has several more options that are not exposed.
In particular for Server/Client cases where the user wants to authorize the server to make API calls, being able to obtain a code that the server can use to obtain a token and a renew token is important. The React package react-google-login offers

<GoogleLogin
        clientId="your-client-id"
        onSuccess={handleGoogleResponse}
        onFailure={handleGoogleResponse}
        cookiePolicy={'single_host_origin'}
        accessType='offline' // To get a non-expiring refresh token
        prompt='consent' // To force the code to allow to obtain a refresh-token each time (otherwise only the first in a session will get a refresh-token
        responseType='code' // Obtain a code to pass to the server
      />;

An added benefit is that the code method is safer than passing a token as documented by Google.

CSS overblown and too opinionated?

Hey Antony,

I've been taking a look at the CSS and how things work, and think its a bit overblown based on how Svelte works.

example for FacebookAuth.svelte in the CSS section there is this

button.facebook-auth:disabled {
  background-color: grey;
}

However, svelte by design will add a unique css class thus rendering this inefficient.

button:disabled {
  background-color: grey;
}

this code above would perform the same task without extra dross. I'm not suggesting to remove the class from the html, as someone might want to add further styling via a global CSS.

In addition to this, I find its quite opinionated in the way it has to be displayed. Things like the button color, text color and button width for me should be adaptable without having to fork and re-write the base.

Suggesting something like this:

<script>
export let buttonColor = "#ff9900";
</script>
<button style="--button-color: {buttonColor}"><!-- inner code --></button>

<style>
button {
  background: var(--button-color);
}
</style>

As I said, I'd rather not fork this so I can continue to get updates if there are any, so I'm thinking there should be 4 new attributes

  1. buttonColor
  2. disabledButtonColor
  3. buttonWidth
  4. textColor

Before I make a PR with this, I just wanted to run it by you to see what your thoughts are?

Can't get Google OAuth to work

Hi ๐Ÿ‘‹

First of all, I'm not sure if this a problem with the library itself. I might be missing something here.

If that is the case, I would really appreciate it if you could still take the time to help me out and perhaps this issue might serve as documentation to others in the future.

So, the problem I'm getting is the following:

  • I've set up the code like the README file exemplifies.
  • When I click the button, it opens the Google page for the user's consent.
  • After consenting, the page closes.
  • Nothing happens on my page. It doesn't redirect, it doesn't log anything.

Here's what the code looks like:

<script lang="ts">
    import Tailwindcss from '../Tailwindcss.svelte';
    import { GoogleAuth } from '@beyonk/svelte-social-auth';
</script>

<style>

</style>

<Tailwindcss/>

<main>
    <div class="bg-white">
        <h1>Login</h1>
        <br/>
        <GoogleAuth clientId={process.env.OAUTH_GOOGLE_CLIENT_ID}
                    on:auth-success={e => console.log(e.detail.user)}
                    on:auth-failure={e => console.log(e)}
        />
    </div>
</main>

I can't figure out why it's not working... Do you see what might be causing this issue?

Thanks in advance :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.