@sync-in/server
Version:
The secure, open-source platform for file storage, sharing, collaboration, and sync
126 lines (125 loc) • 5.38 kB
JavaScript
/*
* Copyright (C) 2012-2025 Johan Legrand <johan.legrand@sync-in.com>
* This file is part of Sync-in | The open source file sync and share solution
* See the LICENSE file for licensing details
*/ "use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "AuthController", {
enumerable: true,
get: function() {
return AuthController;
}
});
const _common = require("@nestjs/common");
const _fastify = require("fastify");
const _userdecorator = require("../applications/users/decorators/user.decorator");
const _usermodel = require("../applications/users/models/user.model");
const _routes = require("./constants/routes");
const _authtokenskipdecorator = require("./decorators/auth-token-skip.decorator");
const _authlocalguard = require("./guards/auth-local.guard");
const _authtokenrefreshguard = require("./guards/auth-token-refresh.guard");
const _authmanagerservice = require("./services/auth-manager.service");
function _ts_decorate(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;
}
function _ts_metadata(k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
}
function _ts_param(paramIndex, decorator) {
return function(target, key) {
decorator(target, key, paramIndex);
};
}
let AuthController = class AuthController {
login(user, res) {
return this.auth.setCookies(user, res);
}
logout(res) {
return this.auth.clearCookies(res);
}
refreshCookies(user, res) {
return this.auth.refreshCookies(user, res);
}
token(user) {
return this.auth.getTokens(user);
}
refreshToken(user) {
return this.auth.getTokens(user, true);
}
constructor(auth){
this.auth = auth;
}
};
_ts_decorate([
(0, _common.Post)(_routes.AUTH_ROUTE.LOGIN),
(0, _common.UseGuards)(_authlocalguard.AuthLocalGuard),
_ts_param(0, (0, _userdecorator.GetUser)()),
_ts_param(1, (0, _common.Res)({
passthrough: true
})),
_ts_metadata("design:type", Function),
_ts_metadata("design:paramtypes", [
typeof _usermodel.UserModel === "undefined" ? Object : _usermodel.UserModel,
typeof _fastify.FastifyReply === "undefined" ? Object : _fastify.FastifyReply
]),
_ts_metadata("design:returntype", typeof Promise === "undefined" ? Object : Promise)
], AuthController.prototype, "login", null);
_ts_decorate([
(0, _common.Post)(_routes.AUTH_ROUTE.LOGOUT),
_ts_param(0, (0, _common.Res)({
passthrough: true
})),
_ts_metadata("design:type", Function),
_ts_metadata("design:paramtypes", [
typeof _fastify.FastifyReply === "undefined" ? Object : _fastify.FastifyReply
]),
_ts_metadata("design:returntype", void 0)
], AuthController.prototype, "logout", null);
_ts_decorate([
(0, _common.Post)(_routes.AUTH_ROUTE.REFRESH),
(0, _common.UseGuards)(_authtokenrefreshguard.AuthTokenRefreshGuard),
_ts_param(0, (0, _userdecorator.GetUser)()),
_ts_param(1, (0, _common.Res)({
passthrough: true
})),
_ts_metadata("design:type", Function),
_ts_metadata("design:paramtypes", [
typeof _usermodel.UserModel === "undefined" ? Object : _usermodel.UserModel,
typeof _fastify.FastifyReply === "undefined" ? Object : _fastify.FastifyReply
]),
_ts_metadata("design:returntype", typeof Promise === "undefined" ? Object : Promise)
], AuthController.prototype, "refreshCookies", null);
_ts_decorate([
(0, _common.Post)(_routes.AUTH_ROUTE.TOKEN),
(0, _common.UseGuards)(_authlocalguard.AuthLocalGuard),
_ts_param(0, (0, _userdecorator.GetUser)()),
_ts_metadata("design:type", Function),
_ts_metadata("design:paramtypes", [
typeof _usermodel.UserModel === "undefined" ? Object : _usermodel.UserModel
]),
_ts_metadata("design:returntype", typeof Promise === "undefined" ? Object : Promise)
], AuthController.prototype, "token", null);
_ts_decorate([
(0, _common.Post)(_routes.AUTH_ROUTE.TOKEN_REFRESH),
(0, _common.UseGuards)(_authtokenrefreshguard.AuthTokenRefreshGuard),
_ts_param(0, (0, _userdecorator.GetUser)()),
_ts_metadata("design:type", Function),
_ts_metadata("design:paramtypes", [
typeof _usermodel.UserModel === "undefined" ? Object : _usermodel.UserModel
]),
_ts_metadata("design:returntype", typeof Promise === "undefined" ? Object : Promise)
], AuthController.prototype, "refreshToken", null);
AuthController = _ts_decorate([
(0, _common.Controller)(_routes.AUTH_ROUTE.BASE),
(0, _authtokenskipdecorator.AuthTokenSkip)(),
_ts_metadata("design:type", Function),
_ts_metadata("design:paramtypes", [
typeof _authmanagerservice.AuthManager === "undefined" ? Object : _authmanagerservice.AuthManager
])
], AuthController);
//# sourceMappingURL=auth.controller.js.map