hippofish/packages/backend/src/models/entities/user-security-key.ts

56 lines
1 KiB
TypeScript
Raw Normal View History

2023-01-13 05:40:33 +01:00
import {
PrimaryColumn,
Entity,
JoinColumn,
Column,
ManyToOne,
Index,
} from "typeorm";
import { User } from "./user.js";
import { id } from "../id.js";
@Entity()
export class UserSecurityKey {
2023-05-29 18:31:02 +02:00
@PrimaryColumn("varchar", {
comment: "Variable-length id given to navigator.credentials.get()",
})
public id: string;
@Index()
@Column(id())
2023-01-13 05:40:33 +01:00
public userId: User["id"];
2023-05-29 18:31:02 +02:00
@ManyToOne((type) => User, {
onDelete: "CASCADE",
})
@JoinColumn()
public user: User | null;
@Index()
2023-05-29 18:31:02 +02:00
@Column("varchar", {
comment:
2023-05-29 18:31:02 +02:00
"Variable-length public key used to verify attestations (hex-encoded).",
})
public publicKey: string;
2023-05-29 18:31:02 +02:00
@Column("timestamp with time zone", {
comment:
2023-05-29 18:31:02 +02:00
"The date of the last time the UserSecurityKey was successfully validated.",
})
public lastUsed: Date;
2023-05-29 18:31:02 +02:00
@Column("varchar", {
comment: "User-defined name for this key",
2021-12-09 15:58:30 +01:00
length: 30,
})
public name: string;
constructor(data: Partial<UserSecurityKey>) {
if (data == null) return;
for (const [k, v] of Object.entries(data)) {
(this as any)[k] = v;
}
}
}