forked from
rocksky.app/rocksky
A decentralized music tracking and discovery platform built on AT Protocol 馃幍
1import { RockskyClient } from "client";
2import fs from "fs/promises";
3import os from "os";
4import path from "path";
5
6export async function whoami(): Promise<string> {
7 const tokenPath = path.join(os.homedir(), ".rocksky", "token.json");
8 try {
9 await fs.access(tokenPath);
10 } catch (err) {
11 return "You are not logged in. Please run `rocksky login <username>.bsky.social` first.";
12 }
13
14 const tokenData = await fs.readFile(tokenPath, "utf-8");
15 const { token } = JSON.parse(tokenData);
16 if (!token) {
17 return "You are not logged in. Please run `rocksky login <username>.bsky.social` first.";
18 }
19
20 const client = new RockskyClient(token);
21 try {
22 const user = await client.getCurrentUser();
23 return `You are logged in as ${user.handle} (${user.displayName}).\nView your profile at: https://rocksky.app/profile/${user.handle}`;
24 } catch (err) {
25 return "Failed to fetch user data. Please check your token and try again.";
26 }
27}