Support passwordless login (EmailProvider) without adapters. #4059
Replies: 7 comments 10 replies
-
Hi, we had a similar issue with that and created a quick and easy in memory adapter using LevelDB (want to change that into solidDB) to have just the store for current active Email Tokens around in space. Maybe it is from interest to share this adapter. Guess you know already this documentation: https://next-auth.js.org/tutorials/creating-a-database-adapter |
Beta Was this translation helpful? Give feedback.
-
Hi, I have rewritten our small Adapter with node-cache while having automatic TTL. The TTL will take care that the Token gets deleted after MaxAge and cannot be used afterwards. Using the Using the To use the You should use the in [...nextauth].js ...
import NodeCache from 'node-cache';
function EmailTokenNodeCacheAdapter(client, options) {
return {
getUserByEmail: async (email) => ({ id: email, email }),
getUserByAccount: async ({ providerAccountId, provider }) => ({ id: providerAccountId, provider }),
updateUser: async (user) => user,
createVerificationToken: async (data) => {
return client.set(data.identifier, data) ? data : null
},
useVerificationToken: async ({ identifier, token }) => {
const data = client.get(identifier);
return (data?.token === token) ? client.take(identifier) : false;
}
}
}
export default NextAuth({
...
adapter: EmailTokenNodeCacheAdapter(new NodeCache({ stdTTL: 24 * 60 * 60, checkperiod: 1 * 60 * 60 })),
...
callbacks: {
async signIn({ user, account, profile, email, credentials }) {
...
},
...
},
...
}); @balazsorban44 @ThangHuuVu - Do you like me to prepare a PR and put the Adapter extra? |
Beta Was this translation helpful? Give feedback.
-
I wonder if looking at the Mail and the Link if it is really necessary to put the Email address into the mail and the link by default? For the link I would prefer the SHA of the Email. Wouldn't that increase security / data privacy?
http://localhost:3000/api/auth/callback/email?callbackUrl=http%3A%2F%2Flocalhost%3A3000%2Fde-DE&token=2a29ba957180bec743ffb985f3ed9c42f0e9d87208f0134c8267b9907c2ce880&email=user.name%40email.com
|
Beta Was this translation helpful? Give feedback.
-
Hey guys, long time not moving forward here. Is there any action I can do or deliver to support? Tom |
Beta Was this translation helpful? Give feedback.
-
I too would find it useful to have either emailProvider work without adapter or have documented a barebones adapter example with only the methods needed being those necessary for the emailProvider to work... |
Beta Was this translation helpful? Give feedback.
-
Okay the above actually quite work for me and I think that is because I am using the emailProvider + other oauth providers. I ended up with this:
Looking at the types a lot of the callbacks let you return null. I am guessing that is fine to do that if I don't have any use for the method. Really all I want is |
Beta Was this translation helpful? Give feedback.
-
My nextjs version: 14 Goal: Setup passwordless authentication with EmailProvider Turns out If anyone is facing the error with
The solution would be to :
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Description 📓
Adapters, though very useful, are limiters because they require a certain database structure that may not make sense for everyone. I think at least you should give users an option to handle database stuff themselves. In OAuth providers and Credentials provider, there is a place where we can do database operations if we don't want to use an adapter (signIn callback and authorize method) but there is no such place for
Email Provider
.Email provider really needs an adapter just in one place (here). My proposal is to call this section conditionally. For example, we can add a method to
EmailProvider
namedcreateVerificationToken
which has a higher priority than the adapter one. When this method is defined in the provider options, theadapter.createVerificationToken
shouldn't be called. this enables us to do something like this:Here is my problem with adapters: #4047 (comment)
UPDATE: The more I discover the source code, the more it seems impossible to do.
How to reproduce ☕️
I described my idea above.
Contributing 🙌🏽
Yes, I am willing to help implement this feature in a PR
Beta Was this translation helpful? Give feedback.
All reactions