feat: Implement token generation logic on api tokens

This commit is contained in:
Faruk AYDIN
2025-04-08 11:22:07 +02:00
parent add8a44f40
commit 59510dcb0a
5 changed files with 42 additions and 18 deletions

View File

@@ -1,17 +1,25 @@
import Base from './base.js';
import crypto from 'crypto';
class ApiToken extends Base {
static tableName = 'api_tokens';
static jsonSchema = {
type: 'object',
required: ['token'],
properties: {
id: { type: 'string', format: 'uuid' },
token: { type: 'string', minLength: 32 },
},
};
async assignToken() {
this.token = crypto.randomBytes(48).toString('hex');
}
async $beforeInsert(queryContext) {
await super.$beforeInsert(queryContext);
await this.assignToken();
}
}
export default ApiToken;