Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4a80bf1c0e | |||
| 05c962d46f | |||
| cf3fef6936 |
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"$schema": "https://schema.tauri.app/config/2",
|
"$schema": "https://schema.tauri.app/config/2",
|
||||||
"productName": "ChatApp",
|
"productName": "ChatApp",
|
||||||
"version": "0.3.2",
|
"version": "0.3.5",
|
||||||
"identifier": "com.meinname.chatapp",
|
"identifier": "com.meinname.chatapp",
|
||||||
"build": {
|
"build": {
|
||||||
"beforeDevCommand": "pnpm vite:dev",
|
"beforeDevCommand": "pnpm vite:dev",
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
|||||||
const status = (error as { status?: number }).status;
|
const status = (error as { status?: number }).status;
|
||||||
if (status === 401 || status === 403) {
|
if (status === 401 || status === 403) {
|
||||||
// Token genuinely invalid — wipe.
|
// Token genuinely invalid — wipe.
|
||||||
await supabase.auth.signOut().catch(() => {
|
await supabase.auth.signOut({ scope: 'local' }).catch(() => {
|
||||||
/* ignore */
|
/* ignore */
|
||||||
});
|
});
|
||||||
setSession(null);
|
setSession(null);
|
||||||
|
|||||||
@@ -39,11 +39,21 @@ export async function setSecretStoreUser(userId: string | null): Promise<void> {
|
|||||||
|
|
||||||
if (userId && isTauriRuntime()) {
|
if (userId && isTauriRuntime()) {
|
||||||
const stronghold = makeStrongholdStore(userId);
|
const stronghold = makeStrongholdStore(userId);
|
||||||
activeBackend = stronghold;
|
|
||||||
try {
|
try {
|
||||||
await migrateLocalStorageToStronghold(userId, PREFIX);
|
// Force a tiny round-trip to verify Stronghold can actually open the
|
||||||
|
// vault on this machine. If not (broken vault file, bundled rust crate
|
||||||
|
// mismatch, etc.) we fall back to localStorage so the rest of the app
|
||||||
|
// remains usable instead of bricking device registration.
|
||||||
|
await stronghold.getSecret('__probe');
|
||||||
|
activeBackend = stronghold;
|
||||||
|
try {
|
||||||
|
await migrateLocalStorageToStronghold(userId, PREFIX);
|
||||||
|
} catch (err: unknown) {
|
||||||
|
console.warn('stronghold migration failed', err);
|
||||||
|
}
|
||||||
} catch (err: unknown) {
|
} catch (err: unknown) {
|
||||||
console.warn('stronghold migration failed', err);
|
console.warn('stronghold init failed — falling back to localStorage', err);
|
||||||
|
activeBackend = localStore;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
activeBackend = localStore;
|
activeBackend = localStore;
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import {
|
|||||||
type MessageWithCipher,
|
type MessageWithCipher,
|
||||||
sendEncryptedMessage,
|
sendEncryptedMessage,
|
||||||
} from '@chat-app/shared/chat';
|
} from '@chat-app/shared/chat';
|
||||||
import { bytesToPgHex, pgHexToBytes } from '@chat-app/shared/supabase';
|
import { bytesToPgHex, pgBytesToBytes } from '@chat-app/shared/supabase';
|
||||||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||||
|
|
||||||
import { devLocalSecretStore } from './secretStore';
|
import { devLocalSecretStore } from './secretStore';
|
||||||
@@ -44,8 +44,8 @@ function rowToMessage(row: Record<string, unknown>): MessageWithCipher {
|
|||||||
editedAt: row.edited_at ? String(row.edited_at) : null,
|
editedAt: row.edited_at ? String(row.edited_at) : null,
|
||||||
deletedAt: row.deleted_at ? String(row.deleted_at) : null,
|
deletedAt: row.deleted_at ? String(row.deleted_at) : null,
|
||||||
createdAt: String(row.created_at),
|
createdAt: String(row.created_at),
|
||||||
ciphertext: pgHexToBytes(String(row.ciphertext ?? '\\x')),
|
ciphertext: pgBytesToBytes(String(row.ciphertext ?? '\\x')),
|
||||||
nonce: pgHexToBytes(String(row.nonce ?? '\\x')),
|
nonce: pgBytesToBytes(String(row.nonce ?? '\\x')),
|
||||||
keyVersion: typeof row.key_version === 'number' ? row.key_version : 1,
|
keyVersion: typeof row.key_version === 'number' ? row.key_version : 1,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,7 +86,11 @@ export async function completeSessionFromUrl(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function signOut(client: AppSupabaseClient): Promise<void> {
|
export async function signOut(client: AppSupabaseClient): Promise<void> {
|
||||||
const { error } = await client.auth.signOut();
|
// `scope: 'local'` only ends the session in THIS client. Without it Supabase
|
||||||
|
// defaults to 'global', which invalidates the user's refresh tokens
|
||||||
|
// everywhere — meaning a logout in the browser would also kick the desktop
|
||||||
|
// app (and vice versa) the next time it tries to refresh its token.
|
||||||
|
const { error } = await client.auth.signOut({ scope: 'local' });
|
||||||
if (error) throw error;
|
if (error) throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,3 +23,20 @@ export function pgHexToBytes(hex: string): Uint8Array {
|
|||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Accepts either:
|
||||||
|
// - PostgREST/REST `\x<hex>` strings (what the .from('table').select() path
|
||||||
|
// returns for bytea), or
|
||||||
|
// - Realtime `postgres_changes` payloads, which encode bytea as plain
|
||||||
|
// base64 (no `\x` prefix).
|
||||||
|
// Useful when the same row can arrive through both paths in the same UI.
|
||||||
|
export function pgBytesToBytes(value: string): Uint8Array {
|
||||||
|
if (value.startsWith('\\x')) {
|
||||||
|
return pgHexToBytes(value);
|
||||||
|
}
|
||||||
|
// Assume base64 (the realtime serializer's default for bytea).
|
||||||
|
const bin = atob(value);
|
||||||
|
const out = new Uint8Array(bin.length);
|
||||||
|
for (let i = 0; i < bin.length; i++) out[i] = bin.charCodeAt(i);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user