#!/bin/bash # Check if the auth token persists across restarts. # Usage: npm run check-token # Reads the token from the running node 1, restarts it, and compares. set -e PORTFILE="/tmp/p2pds-node1.port" if [ ! -f "$PORTFILE" ]; then echo "Node 1 not running. Start with: npm run start:node1" exit 1 fi PORT=$(cat "$PORTFILE") TOKEN_BEFORE=$(curl -s "http://localhost:$PORT/" | grep -o 'const TOKEN = "[^"]*"' | sed 's/const TOKEN = "//;s/"//') echo "Token before restart: ${TOKEN_BEFORE:0:16}..." # Restart npm run start:node1 >/dev/null 2>&1 PORT=$(cat "$PORTFILE") TOKEN_AFTER=$(curl -s "http://localhost:$PORT/" | grep -o 'const TOKEN = "[^"]*"' | sed 's/const TOKEN = "//;s/"//') echo "Token after restart: ${TOKEN_AFTER:0:16}..." if [ "$TOKEN_BEFORE" = "$TOKEN_AFTER" ]; then echo "PASS: Token persisted across restart" else echo "FAIL: Token changed on restart" exit 1 fi