Various AT Protocol integrations with obsidian
20
fork

Configure Feed

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

login in settings

+58 -5
+58 -5
src/settings.ts
··· 1 1 import { App, Notice, PluginSettingTab, Setting } from "obsidian"; 2 2 import type AtmospherePlugin from "./main"; 3 + import { isActorIdentifier } from "@atcute/lexicons/syntax"; 4 + import { OauthServer } from "./lib/oauth"; 5 + import { ATClient } from "./lib/client"; 3 6 4 7 export interface AtProtoSettings { 5 8 identifier: string; ··· 33 36 34 37 if (this.plugin.settings.identifier) { 35 38 new Setting(containerEl) 36 - .setName("Authenticated as") 39 + .setName("Logged in") 37 40 .setDesc(this.plugin.settings.identifier); 38 41 39 42 new Setting(containerEl) 40 43 .setName("Log out") 41 - .setDesc("Clear your authentication and log out") 42 44 .addButton((button) => 43 45 button 44 46 .setButtonText("Log out") ··· 56 58 }) 57 59 ); 58 60 } else { 59 - containerEl.createEl("p", { 60 - text: "You'll be prompted to authenticate via OAuth when you first use the plugin.", 61 - }); 61 + let handleInput: HTMLInputElement; 62 + 63 + new Setting(containerEl) 64 + .setName("Log in") 65 + .setDesc("Enter your Bluesky or AT Protocol handle (e.g., user.bsky.social)") 66 + .addText((text) => { 67 + handleInput = text.inputEl; 68 + text.setPlaceholder("user.bsky.social") 69 + .setValue(""); 70 + }) 71 + .addButton((button) => 72 + button 73 + .setButtonText("Log in") 74 + .setCta() 75 + .onClick(async () => { 76 + const handle = handleInput.value.trim(); 77 + 78 + if (!handle) { 79 + new Notice("Please enter a handle."); 80 + return; 81 + } 82 + 83 + if (!isActorIdentifier(handle)) { 84 + new Notice("Invalid handle format. Please enter a valid AT Protocol handle (e.g., user.bsky.social)."); 85 + return; 86 + } 87 + 88 + try { 89 + button.setDisabled(true); 90 + button.setButtonText("Logging in..."); 91 + 92 + new Notice("Opening browser for authorization..."); 93 + 94 + const oauth = new OauthServer(); 95 + const session = await oauth.authorize(handle); 96 + 97 + this.plugin.session = session; 98 + this.plugin.client = new ATClient(session); 99 + this.plugin.settings.identifier = session.did; 100 + await this.plugin.saveSettings(); 101 + 102 + new Notice(`Successfully authenticated as ${session.handle}`); 103 + 104 + // refresh settings to show authenticated state 105 + this.display(); 106 + } catch (error) { 107 + console.error("Login failed:", error); 108 + const errorMessage = error instanceof Error ? error.message : String(error); 109 + new Notice(`Authentication failed: ${errorMessage}`); 110 + button.setDisabled(false); 111 + button.setButtonText("Log in"); 112 + } 113 + }) 114 + ); 62 115 } 63 116 64 117 new Setting(containerEl)