import {sequelize} from "../app"; import * as crypto from "crypto"; import {DataTypes, InferAttributes, InferCreationAttributes, Model} from "sequelize"; export enum TokenType { API, SESSION } export interface IToken extends Model, InferCreationAttributes> { token?: string clientId: string type?: TokenType userAgent?: string } const TokenSchema = sequelize.define('tokens', { token: { type: DataTypes.STRING, defaultValue: () => crypto.randomBytes(48).toString('hex'), primaryKey: true }, clientId: { type: DataTypes.BIGINT, allowNull: false }, type: { type: DataTypes.STRING, defaultValue: TokenType.API }, userAgent: { type: DataTypes.STRING, allowNull: true } }); export const Token = TokenSchema;