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.
26 lines (25 loc) • 883 B
JavaScript
import { cleanParams } from "../main/utils/params.js";
import { hardConfig } from "../main/config/index.js";
export default async function createNostrAuth(searchParams) {
const { client_id: baseUrl = "", state = "", redirect_uri: redirectUri = "", } = cleanParams(searchParams);
if (!baseUrl || !redirectUri || !state) {
throw new Error("Missing query params");
}
const params = new URLSearchParams({ state });
const response = await fetch(baseUrl + hardConfig.apis.create, {
method: "POST",
headers: { "content-type": "application/x-www-form-urlencoded" },
body: params,
cache: "no-cache",
});
const data = await response.json();
if (!data.lnurl) {
throw new Error("Missing lnurl");
}
return {
data: {
k1: data.k1,
},
query: { state, redirectUri },
};
}