Skip to content

Commit 3c5aeb5

Browse files
committed
Update JWT auth example
1 parent 26c276f commit 3c5aeb5

File tree

5 files changed

+18
-1
lines changed

5 files changed

+18
-1
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const config = {
2+
AUTH_URL: import.meta.env.VITE_AUTH_JWT_URL as string,
3+
};

examples/auth-generate-jwt/javascript/src/script.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as Ably from 'ably';
22
import './styles.css';
3+
import { config } from './config';
34

45
const connectButton = document.querySelector('button') as HTMLButtonElement;
56

@@ -14,7 +15,7 @@ function handleConnect() {
1415
messageOne.textContent = '✓';
1516

1617
const realtimeClient = new Ably.Realtime({
17-
authUrl: 'http://localhost:3001/generate-jwt',
18+
authUrl: config.AUTH_URL || 'http://localhost:3001/generate-jwt',
1819
});
1920

2021
const messageTwo = document.getElementById('message-2');

examples/auth-generate-jwt/javascript/vite-env.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
interface ImportMetaEnv {
22
readonly VITE_ABLY_KEY: string;
3+
readonly VITE_AUTH_URL: string;
34
// Add other environment variables here if needed
45
}
56

src/components/Examples/ExamplesRenderer.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ const ExamplesRenderer = ({
7373
Object.entries(files).forEach(([languageKey, languageFiles]) => {
7474
result[languageKey as LanguageKey] = updateAblyConnectionKey(languageFiles, apiKey, {
7575
NAME: getRandomChannelName(), // Use CHANNEL_NAME as env var key
76+
AUTH_TOKEN_URL: process.env.VITE_AUTH_TOKEN_URL || '',
77+
AUTH_JWT_URL: process.env.VITE_AUTH_JWT_URL || '',
7678
});
7779
});
7880
return result;

src/data/examples/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@ import { Example } from './types';
33
export const DEFAULT_EXAMPLE_LANGUAGES = ['javascript', 'react'];
44

55
export const examples: Example[] = [
6+
{
7+
id: 'auth-generate-jwt',
8+
name: 'Generate JWT',
9+
description: 'Generate a JSON Web Token (JWT) for authenticating users.',
10+
products: ['auth'],
11+
layout: 'single-horizontal',
12+
visibleFiles: ['src/script.ts', 'App.tsx', 'Chat.tsx', 'Home.tsx', 'index.tsx'],
13+
metaTitle: `Build chat history with Ably’s Chat SDK`,
14+
metaDescription: `Implement chat room history with message persistence and replay. Learn how to store, retrieve, and sync past messages in realtime apps.`,
15+
},
616
{
717
id: 'chat-presence',
818
name: 'Chat presence',

0 commit comments

Comments
 (0)