9s-fe-core
Version:
Core functionalities for authentication, configuration, and repository management.
62 lines (61 loc) • 2.77 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.authRepository = void 0;
const base_repository_1 = require("../repository/base_repository");
const env_1 = require("../configs/env");
const repository_1 = require("../repository");
class AuthRepository {
constructor() { }
static getInstance() {
if (!AuthRepository.instance) {
AuthRepository.instance = new AuthRepository();
}
return AuthRepository.instance;
}
/**
* Hàm login
* @param email Email của người dùng
* @param password Mật khẩu của người dùng
* @returns Thông tin phản hồi từ API
*/
login(email, password) {
return __awaiter(this, void 0, void 0, function* () {
const { authEndpoints } = (0, env_1.getConfig)();
const requestData = {
apiUrl: `${location.origin}${authEndpoints.login}`,
httpMethod: repository_1.HttpMethod.POST,
payload: {
email, password, grant_type: 'password',
client_id: process.env.BE_CLIENT_ID,
client_secret: process.env.BE_CLIENT_SECRET,
},
};
console.log('requestData:', JSON.stringify(requestData, null, 2));
return yield base_repository_1.baseRepository.submitRequest(requestData);
});
}
/**
* Lấy thông tin profile của người dùng đã đăng nhập
* @returns Thông tin phản hồi từ API chứa dữ liệu người dùng
*/
getUserProfile() {
return __awaiter(this, void 0, void 0, function* () {
const { apiBaseUrl, authEndpoints } = (0, env_1.getConfig)();
const requestData = {
apiUrl: `${apiBaseUrl}${authEndpoints.profile}`,
httpMethod: repository_1.HttpMethod.GET,
};
return yield base_repository_1.baseRepository.submitRequest(requestData);
});
}
}
exports.authRepository = AuthRepository.getInstance();