File size: 889 Bytes
37fb9ce
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import 'dotenv/config';
import path from 'path';
import dotenv from 'dotenv';
dotenv.config({ path: path.join(__dirname, '../../../../.env') });

import { PrismaClient } from '@prisma/client';

const prisma = new PrismaClient();

async function fixProdToken() {
    const orgId = 'default-org-id';
    const globalToken = process.env.WHATSAPP_ACCESS_TOKEN;

    if (!globalToken) {
        console.error('❌ Missing WHATSAPP_ACCESS_TOKEN in .env');
        return;
    }

    // We set the token to RAW unencrypted text.
    // In production, the decrypt function will safely return it as-is.
    await prisma.organization.update({
        where: { id: orgId },
        data: {
            systemUserToken: globalToken
        }
    });

    console.log(`✅ Restored systemUserToken for ${orgId} to RAW string.`);

    await prisma.$disconnect();
}

fixProdToken().catch(console.error);