Newer
Older
surreal_access_control_system / backend / src / main.ts
import Surreal from 'surrealdb';
import { argv } from 'process';
import { User } from './user';

async function main() {
    // Extract username and password from command-line arguments
    const email = argv[2];
    const password = argv[3];

    if (!email || !password) {
        console.error('Usage: node main.ts <username> <password>');
        process.exit(1);
    }

    const db = new Surreal();

    // Connect to the local SurrealDB instance
    try {
        await db.connect("ws://localhost:8000");
        
        await db.signin({ 
            namespace: 'ts_test', 
            database: 'access_test',
            access: 'account',
            variables: {
                email: email,
                password: password
            }
        });

        const products = await db.select('product');

        console.log('Products:');
        products.forEach(product => {
            console.log(JSON.stringify(product, null, 2));
        });

    } catch (err) {
        console.error("Could not connect to db", err instanceof Error ? err.message : String(err));
    }
}

main();