mirror of
https://github.com/apricote/Listory.git
synced 2026-01-13 21:21:02 +00:00
feat(api): API tokens for authentication
Create and managed simple API tokens for access to the API from external tools.
This commit is contained in:
parent
eda89716ef
commit
8f7eebb806
15 changed files with 614 additions and 154 deletions
77
src/database/migrations/07-CreateApiTokenTable.ts
Normal file
77
src/database/migrations/07-CreateApiTokenTable.ts
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
import {
|
||||
MigrationInterface,
|
||||
QueryRunner,
|
||||
Table,
|
||||
TableIndex,
|
||||
TableForeignKey,
|
||||
} from "typeorm";
|
||||
import { TableColumnOptions } from "typeorm/schema-builder/options/TableColumnOptions";
|
||||
|
||||
const primaryUUIDColumn: TableColumnOptions = {
|
||||
name: "id",
|
||||
type: "uuid",
|
||||
isPrimary: true,
|
||||
isGenerated: true,
|
||||
generationStrategy: "uuid",
|
||||
};
|
||||
|
||||
export class CreateApiTokensTable0000000000007 implements MigrationInterface {
|
||||
async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.createTable(
|
||||
new Table({
|
||||
name: "api_token",
|
||||
columns: [
|
||||
primaryUUIDColumn,
|
||||
{
|
||||
name: "userId",
|
||||
type: "uuid",
|
||||
},
|
||||
{
|
||||
name: "description",
|
||||
type: "varchar",
|
||||
},
|
||||
{
|
||||
name: "token",
|
||||
type: "varchar",
|
||||
isUnique: true,
|
||||
},
|
||||
{
|
||||
name: "createdAt",
|
||||
type: "timestamp",
|
||||
default: "CURRENT_TIMESTAMP",
|
||||
},
|
||||
{
|
||||
name: "lastUsedAt",
|
||||
type: "timestamp",
|
||||
default: "CURRENT_TIMESTAMP",
|
||||
},
|
||||
{
|
||||
name: "revokedAt",
|
||||
type: "timestamp",
|
||||
default: null,
|
||||
isNullable: true,
|
||||
},
|
||||
],
|
||||
indices: [
|
||||
new TableIndex({
|
||||
name: "IDX_API_TOKEN_USER_ID",
|
||||
columnNames: ["userId"],
|
||||
}),
|
||||
],
|
||||
foreignKeys: [
|
||||
new TableForeignKey({
|
||||
name: "FK_API_TOKEN_USER_ID",
|
||||
columnNames: ["userId"],
|
||||
referencedColumnNames: ["id"],
|
||||
referencedTableName: "user",
|
||||
}),
|
||||
],
|
||||
}),
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.dropTable("api_token");
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue