login-auth-services
Version:
Authentication services for Google, GitHub, Microsoft, okta and multi-factor authentication using OTP.
87 lines (86 loc) • 3.35 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.User = void 0;
const typeorm_1 = require("typeorm");
const isMongoDB = process.env.DB_TYPE === "mongodb";
let User = class User {
// Handling different ID strategies for MongoDB and SQL
constructor() {
if (isMongoDB) {
this.id = undefined; // MongoDB uses _id
}
else {
this.id = undefined; // SQL uses auto-increment
}
}
};
__decorate([
(isMongoDB ? (0, typeorm_1.ObjectIdColumn)() : (0, typeorm_1.PrimaryGeneratedColumn)()),
__metadata("design:type", Object)
], User.prototype, "id", void 0);
__decorate([
(0, typeorm_1.Column)({ unique: false }),
__metadata("design:type", String)
], User.prototype, "username", void 0);
__decorate([
(0, typeorm_1.Column)({ unique: true }),
__metadata("design:type", String)
], User.prototype, "email", void 0);
__decorate([
(0, typeorm_1.Column)(),
__metadata("design:type", String)
], User.prototype, "password", void 0);
__decorate([
(0, typeorm_1.Column)(),
__metadata("design:type", String)
], User.prototype, "salt", void 0);
__decorate([
(0, typeorm_1.Column)({ nullable: true }),
__metadata("design:type", String)
], User.prototype, "githubId", void 0);
__decorate([
(0, typeorm_1.Column)({ nullable: true }),
__metadata("design:type", String)
], User.prototype, "googleId", void 0);
__decorate([
(0, typeorm_1.Column)({ nullable: true }),
__metadata("design:type", String)
], User.prototype, "provider", void 0);
__decorate([
(0, typeorm_1.Column)({ nullable: true }),
__metadata("design:type", String)
], User.prototype, "microsoftId", void 0);
__decorate([
(0, typeorm_1.Column)({ nullable: true }),
__metadata("design:type", String)
], User.prototype, "providerId", void 0);
__decorate([
(0, typeorm_1.Column)(),
__metadata("design:type", String)
], User.prototype, "profileUrl", void 0);
__decorate([
(0, typeorm_1.Column)({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" }),
__metadata("design:type", Date)
], User.prototype, "createdAt", void 0);
__decorate([
(0, typeorm_1.Column)({
type: "timestamp",
default: () => "CURRENT_TIMESTAMP",
onUpdate: "CURRENT_TIMESTAMP",
}),
__metadata("design:type", Date)
], User.prototype, "updatedAt", void 0);
User = __decorate([
(0, typeorm_1.Entity)(),
__metadata("design:paramtypes", [])
], User);
exports.User = User;