Something went wrong. Try again.
A decentralized music tracking and discovery platform built on AT Protocol ๐ต rocksky.app
spotify atproto lastfm musicbrainz scrobbling listenbrainz
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657import axios from "axios";import chalk from "chalk";import cors from "cors";import express, { Request, Response } from "express";import fs from "fs/promises";import open from "open";import os from "os";import path from "path";import { c } from "theme";
export async function login(handle: string): Promise<void> { const app = express(); app.use(cors()); app.use(express.json());
const server = app.listen(6996);
app.post("/token", async (req: Request, res: Response) => { console.log(chalk.bold(c.highlight("Login successful!\n"))); console.log( "You can use this session key (Token) to authenticate with the API." ); console.log("Received token (session key):", c.primary(req.body.token));
const tokenPath = path.join(os.homedir(), ".rocksky", "token.json"); await fs.mkdir(path.dirname(tokenPath), { recursive: true }); await fs.writeFile( tokenPath, JSON.stringify({ token: req.body.token }, null, 2) );
res.json({ ok: 1, });
server.close(); });
const response = await axios.post("https://api.rocksky.app/login", { handle, cli: true, });
const redirectUrl = response.data;
if (!redirectUrl.includes("authorize")) { console.error("Failed to login, please check your handle and try again."); server.close(); return; }
console.log("Please visit this URL to authorize the app:"); console.log(c.link(redirectUrl));
open(redirectUrl);}