diff --git a/fusionauth/fa-tenant-creation.js b/fusionauth/fa-tenant-creation.js index 31bb8e3..fb186ce 100644 --- a/fusionauth/fa-tenant-creation.js +++ b/fusionauth/fa-tenant-creation.js @@ -4,7 +4,25 @@ const { FusionAuthClient } = require('@fusionauth/node-client'); const appUrl = 'http://localhost'; const client = new FusionAuthClient('33052c8a-c283-4e96-9d2a-eb1215c69f8f-not-for-prod', 'http://localhost:9011'); +async function deleteTenant(tenantName) { + try { + let response = await client.searchTenants({ + "search": { + "name": tenantName, + } + }); + let tenants = response.successResponse.tenants; + if (tenants.length > 0 && tenants[0].name === tenantName) { + let tenantId = tenants[0].id; + await client.deleteTenant(tenantId); + } + } catch (e) { + console.log(e); + } +} + async function create(tenantName) { + await deleteTenant(tenantName); try { let tenantId = uuid.v4(); await client.createTenant(tenantId, { diff --git a/services/auth-service/index.js b/services/auth-service/index.js index 4e0a7fd..341227d 100644 --- a/services/auth-service/index.js +++ b/services/auth-service/index.js @@ -84,6 +84,12 @@ app.get('/oauth-redirect', async (req, res, next) => { const authCode = `${req.query?.code}`; const userSessionCookie = req.cookies[userSession]; + if (!userSessionCookie) { + console.log('Missing userSession cookie'); + res.redirect(302, '/'); + return; + } + res.clearCookie(userSession); if (!userSessionCookie.clientId || !userSessionCookie.tenant) { console.log('Missing clientId or tenant from cookie');