36 lines
870 B
TypeScript
36 lines
870 B
TypeScript
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<InferAttributes<IToken>, InferCreationAttributes<IToken>> {
|
|
token?: string
|
|
clientId: string
|
|
type?: TokenType
|
|
userAgent?: string
|
|
}
|
|
|
|
const TokenSchema = sequelize.define<IToken>('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; |