Skip to content

Commit

Permalink
deleteTenant fusionauth
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabi-02 committed Jan 17, 2024
1 parent 87f4801 commit 1db310b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
18 changes: 18 additions & 0 deletions fusionauth/fa-tenant-creation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down
6 changes: 6 additions & 0 deletions services/auth-service/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 1db310b

Please sign in to comment.