login-auth-services
Version:
Authentication services for Google, GitHub, Microsoft, okta and multi-factor authentication using OTP.
61 lines (43 loc) • 1.24 kB
text/typescript
import { Entity, Column, PrimaryGeneratedColumn, ObjectIdColumn } from "typeorm";
const isMongoDB = process.env.DB_TYPE === "mongodb";
()
export class User {
@ (isMongoDB ? ObjectIdColumn() : PrimaryGeneratedColumn())
id!: number | string;
({ unique: false })
username!: string;
({ unique: true })
email!: string;
()
password!: string;
()
salt?: string;
({nullable: true})
githubId?:string;
({nullable: true})
googleId?:string;
({ nullable: true })
provider?: string;
({nullable: true})
microsoftId?:string;
({ nullable: true })
providerId?: string;
()
profileUrl?:string;
({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
createdAt?: Date;
({
type: "timestamp",
default: () => "CURRENT_TIMESTAMP",
onUpdate: "CURRENT_TIMESTAMP",
})
updatedAt?: Date;
// Handling different ID strategies for MongoDB and SQL
constructor() {
if (isMongoDB) {
(this as any).id = undefined; // MongoDB uses _id
} else {
(this as any).id = undefined; // SQL uses auto-increment
}
}
}