#!/bin/bash
# Login both users and save tokens
source "$(dirname "$0")/config.sh"

echo "=== Logging in as $USER1_NAME ==="
TOKEN1=$(curl -s -X POST "$BASE_URL/new/token" \
    -d "username=$USER1_NAME" \
    -d "password=$USER1_PASS")
echo "Token1: $TOKEN1"
save_state "TOKEN1" "$TOKEN1"

USER1_ID=$(decode_jwt_sub "$TOKEN1")
echo "User1 ID: $USER1_ID"
save_state "USER1_ID" "$USER1_ID"

echo ""
echo "=== Logging in as $USER2_NAME ==="
TOKEN2=$(curl -s -X POST "$BASE_URL/new/token" \
    -d "username=$USER2_NAME" \
    -d "password=$USER2_PASS")
echo "Token2: $TOKEN2"
save_state "TOKEN2" "$TOKEN2"

USER2_ID=$(decode_jwt_sub "$TOKEN2")
echo "User2 ID: $USER2_ID"
save_state "USER2_ID" "$USER2_ID"
