zents
Version:
ZenTS is a Node.js & TypeScript MVC-Framework for building rich web applications, released as free and open-source software under the MIT License. It is designed for building web applications with modern tools and design patterns.
38 lines • 1.66 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SessionFactory = void 0;
const Session_1 = require("./Session");
const SessionStore_1 = require("./SessionStore");
const SessionStoreAdapterFactory_1 = require("./SessionStoreAdapterFactory");
class SessionFactory {
constructor(securityProviders, databaseContainer) {
this.securityProviders = securityProviders;
this.storeFactory = new SessionStoreAdapterFactory_1.SessionStoreAdapterFactory(databaseContainer);
}
async build(providerKey, context, previouslyLoadedUser) {
const securityProvider = this.securityProviders.get(providerKey);
let user = null;
let sessionId;
if (typeof previouslyLoadedUser !== 'undefined') {
user = previouslyLoadedUser.user;
sessionId = previouslyLoadedUser.sessionId;
}
else {
const authorize = await securityProvider.authorize(context);
if (authorize.isAuth) {
user = authorize.user;
sessionId = authorize.sessionId;
}
}
if (typeof sessionId !== 'string') {
sessionId = securityProvider.generateSessionId();
}
const adapter = this.storeFactory.build(securityProvider.options);
const storeData = await adapter.load(sessionId);
const store = new SessionStore_1.SessionStore(sessionId, storeData, adapter);
const session = new Session_1.Session(sessionId, user, store, adapter, providerKey);
return session;
}
}
exports.SessionFactory = SessionFactory;
//# sourceMappingURL=SessionFactory.js.map