Skip to content

Commit 1d6fea2

Browse files
authored
Merge pull request #99 from JustaName-id/develop
Develop
2 parents f583f7d + 1d073e1 commit 1d6fea2

File tree

3 files changed

+22
-41
lines changed

3 files changed

+22
-41
lines changed

apps/openpassport-static/src/app/app.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export function App() {
1818
try {
1919
const encodedAttestation = btoa(JSON.stringify(attestation));
2020

21-
await axios.get(
21+
const response = await axios.get(
2222
`${import.meta.env.VITE_APP_API_DOMAIN}/credentials/socials/openpassport/callback`,
2323
{
2424
params: {
@@ -27,6 +27,15 @@ export function App() {
2727
},
2828
}
2929
);
30+
31+
const tempDiv = document.createElement('div');
32+
tempDiv.innerHTML = response.data;
33+
34+
const scripts = tempDiv.getElementsByTagName('script');
35+
for (let i = 0; i < scripts.length; i++) {
36+
const script = scripts[i];
37+
eval(script.textContent || '');
38+
}
3039
} catch (error) {
3140
console.error('Error in callback:', error);
3241
}

apps/vc-api/src/api/credentials/credentials.controller.ts

Lines changed: 10 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import {Body, Controller, Get, Inject, Param, Post, Query, Req, Res, UseGuards, OnModuleInit, OnModuleDestroy} from '@nestjs/common';
2-
import { filter, Subject, take } from 'rxjs';
3-
import { v4 as uuidv4 } from 'uuid';
4-
import { Response } from 'express';
1+
import {Body, Controller, Get, Inject, Param, Post, Query, Req, Res, Session, UseGuards} from '@nestjs/common';
52
import {
63
CREDENTIAL_CREATOR_FACADE,
74
ICredentialCreatorFacade
85
} from '../../core/applications/credentials/facade/icredential.facade';
6+
import { Response } from 'express';
97
import { AUTH_CONTROLLER_MAPPER, IcredentialsControllerMapper } from './mapper/icredentials.controller.mapper';
8+
import { v4 as uuidv4 } from 'uuid';
9+
import { filter, Subject, take } from 'rxjs';
1010
import { SubjectData } from './isubject.data';
1111
import { JwtGuard } from '../../guards/jwt.guard';
1212
import {CredentialsGenerateEmailOtpApiRequestQuery} from "./requests/credentials.generate-email-otp.request.api";
@@ -21,10 +21,9 @@ import { ChainId } from '../../core/domain/entities/environment';
2121
type Siwens = { address: string, ens: string, chainId: ChainId };
2222

2323
@Controller('credentials')
24-
export class CredentialsController implements OnModuleInit, OnModuleDestroy {
24+
export class CredentialsController {
2525

2626
private authSubjects: Map<string, Subject<SubjectData>> = new Map();
27-
private heartbeatInterval: NodeJS.Timer;
2827

2928
constructor(
3029
@Inject(CREDENTIAL_CREATOR_FACADE)
@@ -34,32 +33,6 @@ export class CredentialsController implements OnModuleInit, OnModuleDestroy {
3433
private readonly authControllerMapper: IcredentialsControllerMapper
3534
) {}
3635

37-
onModuleInit() {
38-
this.heartbeatInterval = setInterval(() => {
39-
this.sendHeartbeats();
40-
}, 10000);
41-
}
42-
43-
onModuleDestroy() {
44-
if (this.heartbeatInterval) {
45-
clearInterval(this.heartbeatInterval);
46-
}
47-
}
48-
49-
private sendHeartbeats() {
50-
this.authSubjects.forEach((subject, authId) => {
51-
try {
52-
subject.next({
53-
authId,
54-
heartbeat: true,
55-
});
56-
} catch (error) {
57-
this.authSubjects.delete(authId);
58-
throw Error(`Failed to send heartbeat to ${authId}: ${error}`);
59-
}
60-
});
61-
}
62-
6336
@UseGuards(JwtGuard)
6437
@Get('socials/:authName')
6538
async getAuthUrl(
@@ -78,6 +51,7 @@ export class CredentialsController implements OnModuleInit, OnModuleDestroy {
7851
authId
7952
)
8053

54+
8155
res.writeHead(200, {
8256
'Content-Type': 'text/event-stream',
8357
'Cache-Control': 'no-cache',
@@ -87,11 +61,11 @@ export class CredentialsController implements OnModuleInit, OnModuleDestroy {
8761
res.write(`data: ${JSON.stringify({ redirectUrl })}\n\n`);
8862

8963
subject.pipe(
90-
filter(data => data.authId === authId && !data.heartbeat),
64+
filter(data => data.authId === authId),
9165
take(1)
9266
).subscribe(
9367
(data) => {
94-
res.write(`data: ${JSON.stringify({ result: data.result })}\n\n`);
68+
res.write(`data: ${JSON.stringify({ result:data.result })}\n\n`);
9569
res.end();
9670
this.authSubjects.delete(authId);
9771
},
@@ -100,7 +74,7 @@ export class CredentialsController implements OnModuleInit, OnModuleDestroy {
10074
res.end();
10175
this.authSubjects.delete(authId);
10276
}
103-
)
77+
);
10478
}
10579

10680
@Get('socials/:authName/callback')
@@ -121,7 +95,6 @@ export class CredentialsController implements OnModuleInit, OnModuleDestroy {
12195
const subject = this.authSubjects.get(authId);
12296
subject?.next({
12397
authId,
124-
heartbeat: false,
12598
result: {
12699
verifiableCredential,
127100
dataKey
@@ -205,4 +178,4 @@ export class CredentialsController implements OnModuleInit, OnModuleDestroy {
205178

206179
this.authSubjects.delete(authId);
207180
}
208-
}
181+
}

apps/vc-api/src/api/credentials/isubject.data.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ import { VerifiableEthereumEip712Signature2021 } from '../../core/domain/entitie
22

33
export interface SubjectData {
44
authId: string;
5-
heartbeat: boolean
6-
result?: {
5+
result: {
76
verifiableCredential: VerifiableEthereumEip712Signature2021;
87
dataKey: string;
98
};
10-
}
9+
}

0 commit comments

Comments
 (0)