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