Various AT Protocol integrations with obsidian
20
fork

Configure Feed

Select the types of activity you want to include in your feed.

remove oauth modal

-80
-80
src/components/oAuthModal.ts
··· 1 - import { Modal, Notice, setIcon } from "obsidian"; 2 - import type AtmospherePlugin from "../main"; 3 - import { isActorIdentifier } from "@atcute/lexicons/syntax"; 4 - import { OauthServer } from "../lib/oauth"; 5 - import type { OAuthSession } from "@atcute/oauth-node-client"; 6 - 7 - export class OAuthModal extends Modal { 8 - plugin: AtmospherePlugin; 9 - onSuccess?: (session: OAuthSession) => void; 10 - 11 - constructor(plugin: AtmospherePlugin, onSuccess?: (session: OAuthSession) => void) { 12 - super(plugin.app); 13 - this.plugin = plugin; 14 - this.onSuccess = onSuccess; 15 - } 16 - 17 - onOpen() { 18 - const { contentEl } = this; 19 - contentEl.empty(); 20 - contentEl.addClass("atmosphere-detail-modal"); 21 - 22 - contentEl.createEl("h2", { text: "Log in" }); 23 - contentEl.createEl("p", { 24 - text: "Log in with your Bluesky or AT Procol account" 25 - }); 26 - 27 - const handleInput = contentEl.createEl("input", { 28 - type: "text", 29 - placeholder: "Enter your handle (user.bsky.social)" 30 - }); 31 - 32 - const loginButton = contentEl.createEl("button", { text: "Log in" }); 33 - setIcon(loginButton, "enter"); 34 - 35 - loginButton.addEventListener("click", async () => { 36 - const handle = handleInput.value.trim(); 37 - if (!handle) { 38 - new Notice("Please enter a handle."); 39 - return; 40 - } 41 - if (!isActorIdentifier(handle)) { 42 - new Notice("Invalid handle format. Please enter a valid AT Protocol handle (e.g., user.bsky.social)."); 43 - return; 44 - } 45 - 46 - try { 47 - loginButton.disabled = true; 48 - loginButton.textContent = "Starting OAuth flow..."; 49 - 50 - new Notice("Opening browser for authorization..."); 51 - 52 - const oauth = new OauthServer(); 53 - const session = await oauth.authorize(handle); 54 - new Notice(`Successfully authenticated as ${session.handle}`); 55 - 56 - // Call the success callback and close the modal 57 - if (this.onSuccess) { 58 - this.onSuccess(session); 59 - } 60 - this.close(); 61 - } catch (error) { 62 - console.error("OAuth error:", error); 63 - const errorMessage = error instanceof Error ? error.message : String(error); 64 - new Notice(`Authentication failed: ${errorMessage}`); 65 - loginButton.disabled = false; 66 - loginButton.textContent = "Log in"; 67 - } 68 - }); 69 - 70 - handleInput.addEventListener("keypress", (e) => { 71 - if (e.key === "Enter") { 72 - loginButton.click(); 73 - } 74 - }); 75 - handleInput.focus(); 76 - } 77 - onClose() { 78 - this.contentEl.empty(); 79 - } 80 - }