A decentralized music tracking and discovery platform built on AT Protocol 🎵 rocksky.app
spotify atproto lastfm musicbrainz scrobbling listenbrainz
99
fork

Configure Feed

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

Use env credentials in whoami command

When ROCKSKY_IDENTIFIER and ROCKSKY_PASSWORD are present, resolve DID
and handle via the agent, create the user in the local DB if missing,
and print the profile URL. Otherwise fall back to the existing token
file flow.

+36 -7
+36 -7
apps/cli/src/cmd/whoami.ts
··· 1 1 import chalk from "chalk"; 2 2 import { RockskyClient } from "client"; 3 3 import fs from "fs/promises"; 4 + import { createAgent } from "lib/agent"; 5 + import { env } from "lib/env"; 6 + import { getDidAndHandle } from "lib/getDidAndHandle"; 4 7 import os from "os"; 5 8 import path from "path"; 9 + import { createUser } from "./sync"; 10 + import { ctx } from "context"; 11 + import schema from "schema"; 12 + import { eq } from "drizzle-orm"; 6 13 7 14 export async function whoami() { 15 + if (env.ROCKSKY_IDENTIFIER && env.ROCKSKY_PASSWORD) { 16 + const [did, handle] = await getDidAndHandle(); 17 + const agent = await createAgent(did, handle); 18 + let user = await ctx.db 19 + .select() 20 + .from(schema.users) 21 + .where(eq(schema.users.did, did)) 22 + .execute() 23 + .then((rows) => rows[0]); 24 + 25 + if (!user) { 26 + user = await createUser(agent, did, handle); 27 + } 28 + 29 + console.log(`You are logged in as ${user.handle} (${user.displayName}).`); 30 + console.log( 31 + `View your profile at: ${chalk.magenta( 32 + `https://rocksky.app/profile/${user.handle}`, 33 + )}`, 34 + ); 35 + return; 36 + } 8 37 const tokenPath = path.join(os.homedir(), ".rocksky", "token.json"); 9 38 try { 10 39 await fs.access(tokenPath); 11 40 } catch (err) { 12 41 console.error( 13 42 `You are not logged in. Please run ${chalk.greenBright( 14 - "`rocksky login <username>.bsky.social`" 15 - )} first.` 43 + "`rocksky login <username>.bsky.social`", 44 + )} first.`, 16 45 ); 17 46 return; 18 47 } ··· 22 51 if (!token) { 23 52 console.error( 24 53 `You are not logged in. Please run ${chalk.greenBright( 25 - "`rocksky login <username>.bsky.social`" 26 - )} first.` 54 + "`rocksky login <username>.bsky.social`", 55 + )} first.`, 27 56 ); 28 57 return; 29 58 } ··· 34 63 console.log(`You are logged in as ${user.handle} (${user.displayName}).`); 35 64 console.log( 36 65 `View your profile at: ${chalk.magenta( 37 - `https://rocksky.app/profile/${user.handle}` 38 - )}` 66 + `https://rocksky.app/profile/${user.handle}`, 67 + )}`, 39 68 ); 40 69 } catch (err) { 41 70 console.error( 42 - `Failed to fetch user data. Please check your token and try again.` 71 + `Failed to fetch user data. Please check your token and try again.`, 43 72 ); 44 73 } 45 74 }