mirror of
https://github.com/LukeHagar/idn-admin-console.git
synced 2025-12-09 20:47:46 +00:00
Refactor session handling and add logging
This commit is contained in:
@@ -7,34 +7,32 @@ export const actions = {
|
||||
const data = await request.formData();
|
||||
|
||||
const baseUrl = data.get('baseUrl');
|
||||
const tenant = data.get('tenant');
|
||||
const tenantUrl = data.get('tenantUrl');
|
||||
|
||||
if (!baseUrl || !tenantUrl) {
|
||||
redirect(302, '/login');
|
||||
}
|
||||
|
||||
const sessionString = cookies.get('idnSession');
|
||||
const session = { baseUrl: baseUrl.toString(), tenantUrl: tenantUrl.toString() };
|
||||
console.log('session', session);
|
||||
|
||||
if (sessionString) {
|
||||
const idnSessionString = cookies.get('idnSession');
|
||||
|
||||
if (idnSessionString) {
|
||||
// console.log('sessionString', sessionString);
|
||||
|
||||
const session = JSON.parse(sessionString);
|
||||
if (session.org == tenant) {
|
||||
// console.debug('Credential Cache Hit');
|
||||
const idnSession = JSON.parse(idnSessionString);
|
||||
if (idnSession && session.baseUrl.toLowerCase().includes(idnSession.org.toLowerCase())) {
|
||||
console.log('Credential Cache Hit');
|
||||
redirect(302, '/home');
|
||||
} else {
|
||||
// console.debug('Credential Cache Miss');
|
||||
console.log('Credential Cache Miss');
|
||||
}
|
||||
}
|
||||
|
||||
/* @migration task: add path argument */ cookies.set(
|
||||
'session',
|
||||
JSON.stringify({ baseUrl, tenantUrl }),
|
||||
{
|
||||
cookies.set('session', JSON.stringify(session), {
|
||||
path: '/'
|
||||
}
|
||||
);
|
||||
});
|
||||
redirect(302, generateAuthLink(tenantUrl.toString()));
|
||||
}
|
||||
} satisfies Actions;
|
||||
|
||||
Reference in New Issue
Block a user