Skip to content

Commit f4600be

Browse files
committed
Clean up code
1 parent d622da7 commit f4600be

File tree

1 file changed

+1
-53
lines changed

1 file changed

+1
-53
lines changed

integrations/va-auth0/src/index.ts

+1-53
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ type Auth0RuntimeEnvironment = RuntimeEnvironment<
2222
}
2323
>;
2424

25-
// https://dev-qyd2bk185i3mltdi.us.auth0.com/authorize?response_type=code&client_id=xEyiJiDYHQ6JQrOVBvhgXQxhi2KY4cC8&redirect_uri=${installationURL}/visitor-auth/response&state=${location}`
26-
2725
type Auth0RuntimeContext = RuntimeContext<Auth0RuntimeEnvironment>;
2826
const handleFetchEvent: FetchEventCallback<Auth0RuntimeContext> = async (request, context) => {
2927
const { environment } = context;
@@ -33,43 +31,27 @@ const handleFetchEvent: FetchEventCallback<Auth0RuntimeContext> = async (request
3331
base: new URL(installationURL).pathname,
3432
});
3533
router.get('/visitor-auth', async (request) => {
36-
// eslint-disable-next-line no-console
37-
console.log('redirecting bby');
3834
logger.debug('Got a request');
3935
const location = request.query.location;
4036
const issuerBaseUrl = environment.spaceInstallation?.configuration.issuer_base_url;
4137
const clientId = environment.spaceInstallation?.configuration.client_id;
4238

43-
// return Response.json({ url_received: request.url, query: request.query });
44-
// return Response.json({ error: installationURL });
4539
try {
4640
return Response.redirect(
4741
`${issuerBaseUrl}/authorize?response_type=code&client_id=${clientId}&redirect_uri=${installationURL}/visitor-auth/response&state=${location}`
4842
);
4943
} catch (e) {
5044
return Response.json({ error: e.stack });
5145
}
52-
// return Response.redirect(`${installationURL}/visitor-auth/response`);
5346
});
5447

5548
router.get('/visitor-auth/response', async (request) => {
56-
// eslint-disable-next-line no-console
57-
console.log('yaaay');
58-
// redirect to published content URL
5949
if (context.environment.spaceInstallation?.space) {
6050
const space = await context.api.spaces.getSpaceById(
6151
context.environment.spaceInstallation?.space
6252
);
63-
// eslint-disable-next-line no-console
64-
console.log('space', space);
65-
// return Response.json({ url: request.url });
66-
// WORKS;
6753
const obj = space.data;
6854
const privateKey = context.environment.spaceInstallation.configuration.private_key;
69-
// eslint-disable-next-line no-console
70-
console.log('space', obj, privateKey);
71-
// return Response.json({ error: privateKey });
72-
// return Response.redirect('https://www.google.in');
7355
let token;
7456
try {
7557
token = await sign(
@@ -79,7 +61,7 @@ const handleFetchEvent: FetchEventCallback<Auth0RuntimeContext> = async (request
7961
} catch (e) {
8062
return Response.json({ error: e.stack });
8163
}
82-
// return Response.json({ query: request.query });
64+
8365
const issuerBaseUrl = environment.spaceInstallation?.configuration.issuer_base_url;
8466
const clientId = environment.spaceInstallation?.configuration.client_id;
8567
const clientSecret = environment.spaceInstallation?.configuration.client_secret;
@@ -91,9 +73,7 @@ const handleFetchEvent: FetchEventCallback<Auth0RuntimeContext> = async (request
9173
code: `${request.query.code}`,
9274
redirect_uri: `${installationURL}/visitor-auth/response`,
9375
});
94-
// return Response.json({ searchParams });
9576
const url = `${issuerBaseUrl}/oauth/token/`;
96-
// return Response.json({ url });
9777
const resp: any = await fetch(url, {
9878
method: 'POST',
9979
headers: { 'content-type': 'application/x-www-form-urlencoded' },
@@ -106,7 +86,6 @@ const handleFetchEvent: FetchEventCallback<Auth0RuntimeContext> = async (request
10686

10787
if ('access_token' in resp) {
10888
let url;
109-
// return Response.json({ state: request.query.state });
11089
if (request.query.state) {
11190
url = `${obj.urls?.published}${request.query.state}/?jwt_token=${token}`;
11291
} else {
@@ -125,20 +104,8 @@ const handleFetchEvent: FetchEventCallback<Auth0RuntimeContext> = async (request
125104
Error: 'Either ClientId or ClientSecret is missing',
126105
});
127106
}
128-
// // return Response.redirect('https://www.google.no');
129-
// return Response.redirect(
130-
// obj.urls?.published && token
131-
// ? `${obj.urls?.published}/?jwt_token=${token}`
132-
// : 'https://www.google.dk'
133-
// );
134107
}
135-
// eslint-disable-next-line no-console
136-
console.log('noting here');
137-
// return Response.redirect('https://www.google.com');
138108
});
139-
/**
140-
* Handle GitHub App webhook events
141-
*/
142109

143110
let response;
144111
try {
@@ -164,18 +131,6 @@ export default createIntegration({
164131
fetch: handleFetchEvent,
165132
events: {
166133
space_installation_setup: async (event, context) => {
167-
// eslint-disable-next-line no-console
168-
console.log(
169-
'received event',
170-
context.environment.integration.name,
171-
event.installationId,
172-
event.spaceId
173-
);
174-
// eslint-disable-next-line no-console
175-
console.log(
176-
'context.environment.installation?.configuration.private_key',
177-
context.environment.installation?.configuration
178-
);
179134
if (!context.environment.spaceInstallation?.configuration.private_key) {
180135
const res = await context.api.integrations.updateIntegrationSpaceInstallation(
181136
context.environment.integration.name,
@@ -184,16 +139,9 @@ export default createIntegration({
184139
{
185140
configuration: {
186141
private_key: crypto.randomUUID(),
187-
// client_id:
188-
// context.environment.spaceInstallation?.configuration.client_id,
189-
// issuer_base_url:
190-
// context.environment.spaceInstallation?.configuration
191-
// .issuer_base_url,
192142
},
193143
}
194144
);
195-
// eslint-disable-next-line no-console
196-
console.log('recevied response', res.data);
197145
}
198146
},
199147
},

0 commit comments

Comments
 (0)