i-am-bee / bee-api

API backend for Bee
Apache License 2.0
20 stars 8 forks source link

Question: how to get authenticated #42

Closed akihikokuroda closed 2 weeks ago

akihikokuroda commented 3 weeks ago

I'm trying to put the bee-stack in kubernetes. https://github.com/i-am-bee/bee-stack/pull/14 I have an issue accessing to the bee-api from the bee-ui. Is there way to turn off the authentication for debugging purpose? Do I have to update the JWT token?

Thanks!

xjacka commented 3 weeks ago

Authentication can not be turned off. There is a seeder that creates a user and API key (https://github.com/i-am-bee/bee-api/blob/main/seeders/DatabaseSeeder.ts#L41). To access API you can use either the JWT token: https://github.com/i-am-bee/bee-api/blob/main/src/ui/jwt.key or API key: sk-proj-testkey. Simply use an Authentication header with the value Bearer sk-proj-testkey

akihikokuroda commented 3 weeks ago

@xjacka Thanks for response. The seeder is failing with the following error. Do you have any idea? How can I fix it? Thanks!!

ts-node not installed, support for working with TS files might not work
(node:18) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
mikro-orm seeder:run

Seed the database using the seeder class

Options:
      --config   Set path to the ORM configuration file                 [string]
  -c, --class    Seeder class to run                                    [string]
  -v, --version  Show version number                                   [boolean]
  -h, --help     Show help                                             [boolean]

DriverException: Transaction numbers are only allowed on a replica set member or mongos
Query: 
    at MongoExceptionConverter.convertException (/app/node_modules/.pnpm/@mikro-orm+core@6.2.9/node_modules/@mikro-orm/core/platforms/ExceptionConverter.js:8:16)
    at MongoExceptionConverter.convertException (/app/node_modules/.pnpm/@mikro-orm+mongodb@6.2.9_@mikro-orm+core@6.2.9_gcp-metadata@6.1.0/node_modules/@mikro-orm/mongodb/MongoExceptionConverter.js:17:22)
    at MongoDriver.convertException (/app/node_modules/.pnpm/@mikro-orm+core@6.2.9/node_modules/@mikro-orm/core/drivers/DatabaseDriver.js:344:54)
    at /app/node_modules/.pnpm/@mikro-orm+core@6.2.9/node_modules/@mikro-orm/core/drivers/DatabaseDriver.js:348:24
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async MongoDriver.nativeInsertMany (/app/node_modules/.pnpm/@mikro-orm+mongodb@6.2.9_@mikro-orm+core@6.2.9_gcp-metadata@6.1.0/node_modules/@mikro-orm/mongodb/MongoDriver.js:93:21)
    at async ChangeSetPersister.persistNewEntity (/app/node_modules/.pnpm/@mikro-orm+core@6.2.9/node_modules/@mikro-orm/core/unit-of-work/ChangeSetPersister.js:97:21)
    at async ChangeSetPersister.executeInserts (/app/node_modules/.pnpm/@mikro-orm+core@6.2.9/node_modules/@mikro-orm/core/unit-of-work/ChangeSetPersister.js:40:13)
    at async ChangeSetPersister.runForEachSchema (/app/node_modules/.pnpm/@mikro-orm+core@6.2.9/node_modules/@mikro-orm/core/unit-of-work/ChangeSetPersister.js:80:13)
    at async UnitOfWork.commitCreateChangeSets (/app/node_modules/.pnpm/@mikro-orm+core@6.2.9/node_modules/@mikro-orm/core/unit-of-work/UnitOfWork.js:753:9)

    at resultHandler (/app/node_modules/.pnpm/mongodb@6.7.0_gcp-metadata@6.1.0/node_modules/mongodb/lib/bulk/common.js:295:29)
    at /app/node_modules/.pnpm/mongodb@6.7.0_gcp-metadata@6.1.0/node_modules/mongodb/lib/bulk/common.js:346:159
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  code: 20,
  errno: undefined,
  sqlState: undefined,
  sqlMessage: undefined,
  errmsg: undefined,
  errorResponse: {
    ok: 0,
    errmsg: 'Transaction numbers are only allowed on a replica set member or mongos',
    code: 20,
    codeName: 'IllegalOperation'
  },
  ok: 0,
  codeName: 'IllegalOperation',
  writeErrors: [],
  result: BulkWriteResult {
    insertedCount: 0,
    matchedCount: 0,
    modifiedCount: 0,
    deletedCount: 0,
    upsertedCount: 0,
    upsertedIds: {},
    insertedIds: { '0': 'user_6724cecd9da46f6acf3bf8e8' }
  }
}
npm notice
npm notice New minor version of npm available! 10.7.0 -> 10.9.0
npm notice Changelog: https://github.com/npm/cli/releases/tag/v10.9.0
npm notice To update run: npm install -g npm@10.9.0
npm notice
Error occured
pilartomas commented 3 weeks ago

@akihikokuroda The issue is that your MongoDB database isn't running as replicaset which is required by the ORM. It is suggested to use Bee Stack to bootstrap infrastructure in order to avoid these technicalities. https://github.com/i-am-bee/bee-stack?tab=readme-ov-file#advanced-

akihikokuroda commented 2 weeks ago

@pilartomas Thanks! It solved the issue.