Repository Public
1#!/usr/bin/env bash2# Author: Simon-Pierre Boucher — contact@spboucher.ai3# File: Scripts/dev-session.sh4# Description: Prints a session token of the TEST backend (Scripts/backend-dev.sh), obtained through the real device-link endpoints and approved in the test database.5#6# Development only: this never touches production (the approval is written into the local test database).7set -euo pipefail8. /tmp/spmusic-backend-dev/env9PSQL=/opt/homebrew/opt/postgresql@17/bin/psql10$PSQL -Atqc "DELETE FROM rate_limits" "$SPMUSIC_TEST_DB" >/dev/null11START="$(curl -fsS -X POST -H 'content-type: application/json' -d '{"deviceName":"dev"}' "$SPMUSIC_TEST_URL/api/v1/auth/device/start")"12CODE="$(python3 -c 'import json,sys; print(json.loads(sys.argv[1])["userCode"])' "$START")"13DEV="$(python3 -c 'import json,sys; print(json.loads(sys.argv[1])["deviceCode"])' "$START")"14$PSQL -Atqc "UPDATE device_links SET approved_by = (SELECT id FROM users WHERE email = '${1:-owner@example.test}'), decided_at = now() WHERE user_code = '$CODE'" "$SPMUSIC_TEST_DB" >/dev/null15curl -fsS -X POST -H 'content-type: application/json' -d "{\"deviceCode\":\"$DEV\"}" "$SPMUSIC_TEST_URL/api/v1/auth/device/poll" | python3 -c 'import json,sys; print(json.load(sys.stdin)["sessionToken"])'16