next-auth-pubkey
Version:
A light-weight Lightning and Nostr auth provider for your Next.js app that's entirely self-hosted and plugs seamlessly into the next-auth framework.
31 lines (30 loc) • 868 B
JavaScript
import QRCode from "qrcode";
import { colorSchemeDark } from "../main/config/default.js";
/**
* An async function that generates a QR code.
*
* @param {String} data - data to be made into a QR code
* @param {String} config - the `next-auth-pubkey` config object
*
* @returns {Object}
* @returns {String} data - a base64 encoded png/jpg OR svg XML markup
* @returns {String} type - image type: "svg" | "png" | "jpg"
*/
const generateQr = async (data, config) => {
const theme = config?.theme || colorSchemeDark;
const options = {
color: {
dark: theme.qrForeground,
light: theme.qrBackground,
},
margin: theme.qrMargin,
};
return {
data: (await QRCode.toString(data, {
...options,
type: "svg",
})),
type: "svg",
};
};
export default generateQr;