Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@profullstack/libsql-pg": "^0.1.4",
"@profullstack/openprofile": "^0.2.0",
"@profullstack/player": "0.16.0",
"@profullstack/profile": "0.1.6",
"@profullstack/profile": "0.1.7",
"@profullstack/scraper-daemon": "0.3.0",
"@profullstack/submit-feed": "^0.1.3",
"@profullstack/throttle": "^0.4.1",
Expand Down
6 changes: 6 additions & 0 deletions src/app/api/v1/coinpay/oauth/callback/route.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { cookies } from "next/headers";
import { saveOpenProfileContact } from "@profullstack/profile";
import { profileStore } from "@/lib/profile";
import { finishSignIn, sameState } from "@profullstack/coinpay-onboard/oauth";
import { currentUser, startSession } from "@/lib/auth/session";
import {
Expand Down Expand Up @@ -59,6 +61,10 @@ export async function GET(req: Request) {
dbCoinpayStore(),
);
if (!result.ok) return fail(result.code);
if (pending.mode === "connect" && claims.openprofile_url) {
try { await saveOpenProfileContact(profileStore(), String(result.userId), claims.openprofile_url); }
catch { console.warn("[coinpay] OpenProfile import skipped"); }
}

if (pending.mode === "connect") return back("/account?coinpay=connected");
await startSession(result.userId);
Expand Down
2 changes: 1 addition & 1 deletion src/components/ProfileForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default function ProfileForm({ initial }: { initial: Values }) {

return (
<form onSubmit={save}>
<ProfileFields key={JSON.stringify(values)} defaultValues={values} errors={errors} idPrefix="account-" />
<ProfileFields key={JSON.stringify(values)} defaultValues={values} errors={errors} idPrefix="account-" importOpenProfile/>
<button className="btn" type="submit" disabled={busy}>
{busy ? "Saving…" : "Save details"}
</button>
Expand Down
7 changes: 4 additions & 3 deletions src/lib/auth/coinpay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export function decodePending(raw: string | undefined): PendingAuth | null {
}
}

export type CoinpayClaims = { sub: string; email: string | null; name: string | null };
export type CoinpayClaims = { sub: string; email: string | null; name: string | null; openprofile_url?: string };

export type IdentityRow = {
user_id: number;
Expand Down Expand Up @@ -190,10 +190,11 @@ export function canDisconnect(user: { email: string }, passkeyCount: number): bo
}

/** Trims what userinfo returned to what is stored; the email is contact info only. */
export function claimsFrom(r: { sub: string; email: string | null; name: string | null }): CoinpayClaims {
export function claimsFrom(r: { sub: string; email: string | null; name: string | null; userinfo?: object }): CoinpayClaims {
const email = typeof r.email === "string" && r.email.includes("@") ? r.email.slice(0, 320) : null;
const name = typeof r.name === "string" && r.name.trim() ? r.name.trim().slice(0, 200) : null;
return { sub: r.sub, email, name };
const userinfo = r.userinfo as { openprofile_url?: unknown } | undefined;
return { sub: r.sub, email, name, ...(typeof userinfo?.openprofile_url === "string" ? { openprofile_url: userinfo.openprofile_url } : {}) };
}

const MESSAGES: Record<string, string> = {
Expand Down
Loading