Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions sdks/typescript/examples/quickstart-chat/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ export type PrettyMessage = {
text: string;
};

const SERVER_URI = 'ws://localhost:3000';
const MODULE_NAME = 'quickstart-chat';
// Key to store the auth token in local storage.
const LOCAL_STORAGE_TOKEN_KEY = `${SERVER_URI}/${MODULE_NAME}/auth_token`;

function useMessages(conn: DbConnection | null): Message[] {
const [messages, setMessages] = useState<Message[]>([]);

Expand Down Expand Up @@ -107,7 +112,7 @@ function App() {
) => {
setIdentity(identity);
setConnected(true);
localStorage.setItem('auth_token', token);
localStorage.setItem(LOCAL_STORAGE_TOKEN_KEY, token);
console.log(
'Connected to SpacetimeDB with identity:',
identity.toHexString()
Expand All @@ -130,9 +135,9 @@ function App() {

setConn(
DbConnection.builder()
.withUri('ws://localhost:3000')
.withModuleName('quickstart-chat')
.withToken(localStorage.getItem('auth_token') || '')
.withUri(SERVER_URI)
.withModuleName(MODULE_NAME)
.withToken(localStorage.getItem(LOCAL_STORAGE_TOKEN_KEY) || '')
.onConnect(onConnect)
.onDisconnect(onDisconnect)
.onConnectError(onConnectError)
Expand Down
Loading