Replies: 3 comments 3 replies
-
Something we're looking into is adding tokens to Lucia. This will make it easier to create and validate tokens for verification links and one-time passwords. When that's completed, I think we can something similar to OAuth integration. |
Beta Was this translation helpful? Give feedback.
-
i'm wrote this - just about to test it =>
```
import MagicLinkModel from "$lib/server/models/MagicLinkModel.js"
import crypto from 'crypto'
import { nanoid } from "nanoid";
class MagicLink {
constructor(auth, configs) {
this.auth = auth;
this.callbackUrl = configs.callbackUrl;
this.authSecret = configs.authSecret
}
auth;
getAuthorizationUrl = async (email) => {
email = email.trim().toLowerCase()
const id = nanoid(20)
const model = await MagicLinkModel.create({ _id, email })
return this.callbackUrl + "/?code=" + id;
};
validateCallback = async (code) => {
const magiclink = await MagicLinkModel.findById(code)
if(!magiclink) {
throw Error("no such")
}
const { email } = magiclink
const hash = crypto.createHash('md5').update('some_string').digest("hex")
const magiclinkUser = {
picture: "https://www.gravatar.com/avatar/" + hash,
email
}
let existingUser = null;
try {
existingUser = await this.auth.getUserByProviderId("magiclink", email);
}
catch {
// existingUser is null
}
return {
createUser: async (userAttributes = {}) => {
return await this.auth.createUser("magiclink", email, {
attributes: userAttributes
});
},
existingUser,
providerUser: magiclinkUser
};
};
}
const magiclink = (auth, configs) => {
return new MagicLink(auth, configs);
};
export default magiclink;
…On Fri, Dec 16, 2022 at 12:27 PM pilcrowOnPaper ***@***.***> wrote:
Something we're looking into is adding tokens to Lucia. This will make it
easier to create and validate tokens for verification links and one-time
passwords. When that's completed, I think we can something similar to OAuth
integration.
—
Reply to this email directly, view it on GitHub
<#257 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAAGNC5G7OJ6J2ZQKMMMVTWNRG27ANCNFSM6AAAAAATATE6A4>
.
You are receiving this because you authored the thread.Message ID:
***@***.***
com>
|
Beta Was this translation helpful? Give feedback.
-
@pilcrowonpaper would love this in v3 guides. passwordless login is very common as a developer. hate it as a user though as i can't use password manager. edit: it is already there. just the docs are missing a search function 🤜 https://v3.lucia-auth.com/guides/email-and-password/email-verification-codes |
Beta Was this translation helpful? Give feedback.
-
It would be great to add this / have a guide for it
Beta Was this translation helpful? Give feedback.
All reactions