Skip to content

Commit 5d7b4c2

Browse files
authored
Improve and Update Server, React Client, Angular Client (#6)
* update react dependencies to address vulns * update dependencies * Ensure react app and server are working properly together * Angular application works with token fetching * remove values from env * Clarify user key
1 parent 29ca6e2 commit 5d7b4c2

File tree

11 files changed

+1972
-17723
lines changed

11 files changed

+1972
-17723
lines changed

.prettierrc.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"semi": true,
3+
"singleQuote": true,
4+
"trailingComma": "all",
5+
"bracketSpacing": true,
6+
"tabWidth": 2
7+
}

client-angular/src/app/app.config.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ import {
66
import { provideRouter } from '@angular/router';
77

88
import { routes } from './app.routes';
9+
import { provideHttpClient } from '@angular/common/http';
910

1011
export const appConfig: ApplicationConfig = {
1112
providers: [
1213
provideBrowserGlobalErrorListeners(),
13-
provideZoneChangeDetection({ eventCoalescing: true }),
14+
provideHttpClient(),
1415
provideRouter(routes),
16+
provideZoneChangeDetection({ eventCoalescing: true }),
1517
],
1618
};

client-angular/src/app/app.html

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,18 @@
115115
<option value="default">Default Theme</option>
116116
<option value="example">Example Theme</option>
117117
</select>
118-
119118
</div>
120-
<em-beddable
121-
token="eyJhbGciOiJIUzI1NiJ9.eyJzZWN1cml0eVRva2VuSWQiOiIyY2M0ZDg3Ni00ZmJhLTRmZWYtODg2NS00ZDYxYjgwNjdlOGEiLCJpYXQiOjE3NTYxMjYzNTEsImV4cCI6MTc1NjczMTE1MX0.6ZIRGvEgfH-e-GW3Eejf-O0sURTfNDTatdeUM0JHxKM"
122-
[attr.client-context]="clientContext()"
123-
style="width: 100%">
124-
</em-beddable>
125-
119+
@if(token) {
120+
<em-beddable
121+
[token]="token"
122+
[attr.client-context]="clientContext()"
123+
style="width: 100%"
124+
>
125+
</em-beddable>
126+
}
127+
@else {
128+
<div>Loading ...</div>
129+
}
130+
</div>
131+
</main>
126132
<router-outlet />

client-angular/src/app/app.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
1+
/*
2+
*
3+
* NOTE: This demo does not use the server in `/server` - that's for the react client
4+
*
5+
*/
16
import { Component, CUSTOM_ELEMENTS_SCHEMA, signal } from '@angular/core';
27
import { RouterOutlet } from '@angular/router';
8+
import { HttpClient } from '@angular/common/http';
9+
10+
// Uncomment the correct region
11+
const BASE_URL = 'https://api.eu.embeddable.com'; // EU region
12+
// const BASE_URL = 'https://api.us.embeddable.com'; // US region
13+
14+
const API_KEY = ''; // Your API Key
15+
const EMBEDDABLE_ID = ''; // Your Embeddable ID
16+
const USER_KEY = 'example@yourdomain.com'; // unique key (usually email address) representing current user
317

418
@Component({
519
imports: [RouterOutlet],
@@ -9,9 +23,18 @@ import { RouterOutlet } from '@angular/router';
923
})
1024
export class App {
1125
/* Variables */
26+
token: string | null = null;
1227
protected theme = 'default';
1328
protected readonly title = signal('angular-example');
1429

30+
/* Constructor */
31+
constructor(private http: HttpClient) {}
32+
33+
/* On Init */
34+
ngOnInit() {
35+
this.fetchToken();
36+
}
37+
1538
/* Methods */
1639
protected readonly clientContext = signal(
1740
JSON.stringify({ theme: this.theme })
@@ -20,4 +43,27 @@ export class App {
2043
this.theme = (event.target as HTMLSelectElement).value;
2144
this.clientContext.set(JSON.stringify({ theme: this.theme }));
2245
}
46+
47+
private fetchToken() {
48+
this.http
49+
.post<{ token: string }>(
50+
`${BASE_URL}/api/v1/security-token`,
51+
{
52+
embeddableId: EMBEDDABLE_ID,
53+
expiryInSeconds: 60 * 60 * 24 * 7,
54+
securityContext: {}, // Add your security context here
55+
user: USER_KEY,
56+
},
57+
{
58+
headers: {
59+
'Content-Type': 'application/json',
60+
Accept: 'application/json',
61+
Authorization: `Bearer ${API_KEY}`, // Add your API key here
62+
},
63+
}
64+
)
65+
.subscribe((json) => {
66+
this.token = json.token;
67+
});
68+
}
2369
}

0 commit comments

Comments
 (0)