cascade deletes of auth method/session FKs

This commit is contained in:
Erin 2023-11-12 16:05:51 -05:00
parent 1e57731b08
commit 957cc8f38c
2 changed files with 8 additions and 2 deletions

View file

@ -15,7 +15,10 @@ export class AuthMethod {
@Column({type: 'varchar', length: 500, nullable: false})
userIdentifier!: string;
@ManyToOne(() => User, user => user.authMethods)
@ManyToOne(() => User, user => user.authMethods, {
cascade: ['remove'],
onDelete: 'CASCADE',
})
user!: User;
@BeforeInsert()

View file

@ -10,7 +10,10 @@ export class AuthSession {
@PrimaryColumn({type: 'varchar', length: 26, nullable: false})
id = ulidMonotonic();
@ManyToOne(() => AuthMethod, authMethod => authMethod.id, {nullable: false})
@ManyToOne(() => AuthMethod, authMethod => authMethod.id, {
cascade: ['remove'],
onDelete: 'CASCADE',
})
authMethod!: AuthMethod;
// TODO expiration of sessions?