#!/bin/bash
# Script to create Strapi API token via command line
# Run this on the VPS: ssh root@109.199.109.108 "bash -s" < create-strapi-token.sh

echo "Creating Strapi API token..."

# Execute inside the CMS container
docker exec placebo-cms node -e "
const strapi = require('@strapi/strapi');

(async () => {
  try {
    const app = await strapi.createStrapi().load();
    
    const tokenService = app.service('admin::api-token');
    
    const token = await tokenService.create({
      name: 'Backend Integration',
      description: 'Token for backend to fetch articles',
      type: 'read-only',
      permissions: [],
      lifespan: null,
    });

    console.log('\n✅ API Token created successfully!');
    console.log('\nCopy this token to Coolify as STRAPI_API_TOKEN:');
    console.log(token.accessKey);
    console.log('');
    
    process.exit(0);
  } catch (error) {
    console.error('❌ Error:', error.message);
    process.exit(1);
  }
})();
"
