next-auth icon indicating copy to clipboard operation
next-auth copied to clipboard

Google One Tap

Open keslert opened this issue 5 years ago • 29 comments

Is it possible to use next-auth with Google One Tap?

keslert avatar Jan 07 '21 13:01 keslert

I didn't know about this but its really interesting! Thanks for raising this.

iaincollins avatar Jan 07 '21 15:01 iaincollins

Yep, I'm starting to see it used more and more around the web. And the stats I've seen around it show that it has a substantial improvement on signups.

keslert avatar Jan 07 '21 15:01 keslert

also interested to see the best method of implementation is

asdutoit avatar Feb 25 '21 18:02 asdutoit

I'm really curious as well how you would implement something like this with next-auth.

edustef avatar May 30 '21 16:05 edustef

Anyone still waiting?

arcavid avatar Sep 04 '21 06:09 arcavid

I've just looked at this video https://youtu.be/qS4dY7syQwA and got some ideas how to integrate it into NextAuth.js

I cannot say I'll prioritize it, but I happily reopened the issue to track this.

If anyone wants to jump on it and try to implement, please do!

balazsorban44 avatar Sep 04 '21 08:09 balazsorban44

We at hypersay.events already have one-tap implemented with next-auth. It's a matter of creating a custom credentials provider. If anybody is interested I could try to write an article. Screenshot_20211001_132219

ramiel avatar Oct 01 '21 11:10 ramiel

Hi Fabrizio, I am definitely interested and would appreciate and assistance in this regard. Thanks!

On Fri, Oct 1, 2021 at 1:24 PM Fabrizio Ruggeri @.***> wrote:

We at hypersay.events already have one-tap implemented with next-auth. It's a matter of creating a custom credentials provider. If anybody is interested I could try to write an article. [image: Screenshot_20211001_132219] https://user-images.githubusercontent.com/324687/135612033-e1c455c0-4768-4e44-b24a-40d9a1adbb88.png

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/nextauthjs/next-auth/issues/1058#issuecomment-932145171, or unsubscribe https://github.com/notifications/unsubscribe-auth/AE2NP4W7BSYWPIS43VZUF53UEWK5RANCNFSM4VY6VQIQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

asdutoit avatar Oct 01 '21 11:10 asdutoit

@ramiel please do! Email me or write me on twitter if you need any details, I would like to have a look!

balazsorban44 avatar Oct 01 '21 12:10 balazsorban44

@ramiel Please help us all!

arcavid avatar Oct 02 '21 01:10 arcavid

👍 I'm going to wrap up everything in the next few days.

ramiel avatar Oct 02 '21 08:10 ramiel

I got a sneak-peak of @ramiel's post, and it's super nice! 👀 I think we can add support for it and have it integrated (partially) into the core. There will be a small code snippet to copy for the front-end part, but not that bad!

balazsorban44 avatar Oct 03 '21 00:10 balazsorban44

Awesome thanks so much

On Sun, 03 Oct 2021 at 02:05, Balázs Orbán @.***> wrote:

I got a sneak-peak of @ramiel https://github.com/ramiel's post, and it's super nice! 👀 I think we can add support for it and have it integrated (partially) into the core. There will be a small code snippet to copy for the front-end part, but not that bad!

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/nextauthjs/next-auth/issues/1058#issuecomment-932836822, or unsubscribe https://github.com/notifications/unsubscribe-auth/AE2NP4S5XHH52ZADEISTQ3TUE6M47ANCNFSM4VY6VQIQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

asdutoit avatar Oct 03 '21 05:10 asdutoit

And finaly here the tutorial: https://www.ramielcreations.com/next-auth-google-one-tap

Many thanks to @balazsorban44 for help and suggestions

ramiel avatar Oct 03 '21 07:10 ramiel

Fantastic, thanks @ramiel & @balazsorban44, will try it out later this evening. Appreciate your efforts!

asdutoit avatar Oct 03 '21 09:10 asdutoit

https://twitter.com/nextauthjs/status/1444604464837632001 🙌

balazsorban44 avatar Oct 03 '21 10:10 balazsorban44

@keslert it is now! :slightly_smiling_face: I will close this for now, but we might revisit it in the future if we could provide better integration or even built-in support. Busy with other stuff, so don't hold your breath. ut @ramiel's article should get you started.

balazsorban44 avatar Oct 03 '21 10:10 balazsorban44

Awesome, thanks @ramiel!

keslert avatar Oct 03 '21 13:10 keslert

Hi @balazsorban44 & @ramiel,

Thanks for the tutorial. I got pretty far but encountered the following issues:

  • Upon authenticating, the one-tap window reopens.
  • The Session object returns an empty "user" object.

https://user-images.githubusercontent.com/20240370/135831893-5602d2b0-6a81-4029-905c-aaf42bda096a.mp4

Notes:

  • I used Next-Auth version 3, not the new beta 4.
  • I used a custom DB connection for sake of testing. (Data gets loaded to the MongoDB DB just fine. No problems there)

What am I missing/doing wrong that prevents the authentication from completing? My code is available here: Google One-Tap using Next-Auth

If possible, could you provide a minimum working solution to Github that we can download and work from?

Thanks in advance

asdutoit avatar Oct 04 '21 09:10 asdutoit

Hello @asdutoit I had a look at your code an I think you're returning an array of users instead of a single one from your DB.

const user = await db.collection("users").find({ email }).toArray();

// later you return an array (the name of the variable is misleading)
return user

Also your code is not correct because you're defining the user as const on line 101 and then trying to reassign on line 107.

I think you should use findOne instead of find

let user = await db.collection("users").findOne({ email })
if (!user) {
  user = await db.collection("users").insertOne({
    name: [given_name, family_name].join(" "),
    email,
    image,
    emailVerified: email_verified ? new Date() : undefined,
  });
}

ramiel avatar Oct 04 '21 10:10 ramiel