Some checks are pending
Automatisch Backend Tests / test (push) Waiting to run
Automatisch CI / linter (push) Waiting to run
Automatisch CI / start-backend-server (push) Waiting to run
Automatisch CI / start-backend-worker (push) Waiting to run
Automatisch CI / build-web (push) Waiting to run
Automatisch UI Tests / test (push) Waiting to run
14 lines
510 B
JavaScript
14 lines
510 B
JavaScript
import crypto from 'crypto';
|
|
import AccessToken from '../../src/models/access-token.js';
|
|
import { createUser } from './user.js';
|
|
|
|
export const createAccessToken = async (params = {}) => {
|
|
params.userId = params.userId || (await createUser()).id;
|
|
params.token = params.token || (await crypto.randomBytes(48).toString('hex'));
|
|
params.expiresIn = params.expiresIn || 14 * 24 * 60 * 60; // 14 days in seconds
|
|
|
|
const accessToken = await AccessToken.query().insertAndFetch(params);
|
|
|
|
return accessToken;
|
|
};
|