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
6 changes: 4 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 @@ -47,7 +47,7 @@
"@profullstack/cli": "^0.1.0",
"@profullstack/footer": "latest",
"@profullstack/hqtui": "^0.11.1",
"@profullstack/profile": "0.1.6",
"@profullstack/profile": "0.1.7",
"@profullstack/synconfig": "^0.1.3",
"@profullstack/x402-gateway": "^0.16.1",
"highlight.js": "^11.12.0",
Expand Down
21 changes: 19 additions & 2 deletions server/coinpay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import {
type User,
} from "./store.ts";
import { createHash } from "node:crypto";
import { saveOpenProfileContact } from "@profullstack/profile";
import { profiles } from "./profile.ts";

export const COINPAY_SCOPES = "openid profile email";
const PROVIDER = "coinpay";
Expand All @@ -52,7 +54,7 @@ export type Identity = {
createdAt: string;
lastUsedAt: string;
};
type UserInfo = { sub: string; name: string | null; email: string | null };
type UserInfo = { sub: string; name: string | null; email: string | null; openprofileUrl: string | null };

export function coinpayOptions(env = process.env): CoinPayOptions {
return {
Expand Down Expand Up @@ -165,7 +167,20 @@ export class CoinPay {
"CoinPay did not accept this access token. It may have expired; get a new one.",
);
// email_verified is always false on CoinPay. The address is kept for display only.
return { sub, name: str(result.body.name), email: str(result.body.email) };
return {
sub,
name: str(result.body.name),
email: str(result.body.email),
openprofileUrl: str(result.body.openprofile_url),
};
}
private async importProfile(userId: string, url: string | null) {
if (!url) return;
try {
await saveOpenProfileContact(await profiles(this.store.db).ready, userId, url);
} catch (error) {
console.warn("[coinpay] OpenProfile import skipped:", error instanceof Error ? error.message : error);
}
}
identities(userId: string): Identity[] {
return this.store.all<Identity>(
Expand Down Expand Up @@ -433,9 +448,11 @@ export class CoinPay {
const current = this.accounts.authenticate(this.accounts.token(request));
if (current) {
this.link(current, info);
await this.importProfile(current.id, info.openprofileUrl);
return go(pending.next ?? "/account?coinpay=linked");
}
const signedIn = this.provision(info, "signin");
await this.importProfile(signedIn.id, info.openprofileUrl);
const session = this.accounts.startSession(
signedIn.id,
this.accounts.token(request),
Expand Down
2 changes: 1 addition & 1 deletion site/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ write("account/index.html", readFileSync(join(here, "assets/account.html"), "utf
.replace("__ACCOUNT_SCRIPT__", accountScript).replace("__ACCOUNT_STYLES__", accountCss)
.replace("__PROFILE_SCRIPT__", profileScript)
.replace("__SIGNUP_FIELDS__", renderProfileFields({ fields: profileFields, idPrefix: "signup-" }))
.replace("__DETAILS_FIELDS__", renderProfileFields({ fields: profileFields, idPrefix: "details-" })));
.replace("__DETAILS_FIELDS__", renderProfileFields({ fields: profileFields, idPrefix: "details-", importOpenProfile: true })));
const sharedCss = asset("styles.css", css);
const adminCss = asset("admin.css", readFileSync(join(here, "assets/admin.css"), "utf8"));
const adminBundle = await Bun.build({ entrypoints: [join(here, "admin.ts")], target: "browser", minify: true });
Expand Down
2 changes: 1 addition & 1 deletion site/test/accounts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ test("verified signup, profile, persistence, sign-out, and return sign-in", asyn
await expect(page.getByText("Email verified", { exact: true })).toBeVisible();
await page.getByLabel("Display name").fill("Alex Reader");
await page.getByRole("button", { name: "Save name" }).click();
await expect(page.getByRole("status")).toContainText("Your name has been saved.");
await expect(page.locator("#status")).toContainText("Your name has been saved.");
await page.reload();
await expect(page.getByLabel("Display name")).toHaveValue("Alex Reader");
expect(await page.evaluate(() => document.cookie)).not.toContain("readm3_session");
Expand Down
Loading