Skip to content

Commit

Permalink
1.integrate with sse event change
Browse files Browse the repository at this point in the history
  • Loading branch information
cwangsmv committed Dec 5, 2024
1 parent e7a062a commit 1f9ea66
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ interface FileChangedEvent {
interface VaultKeyChangeEvent {
type: 'VaultKeyChanged';
topic: string;
sessionId: string;
};

export interface UserPresence {
Expand Down Expand Up @@ -186,6 +187,7 @@ export const InsomniaEventStreamProvider: FC<PropsWithChildren> = ({ children })
} else if (event.type === 'VaultKeyChanged') {
clearVaultKeyFetcher.submit({
organizations: organizations?.map(org => org.id) || [],
sessionId: event.sessionId,
}, {
action: '/auth/clearVaultKey',
method: 'POST',
Expand Down
10 changes: 6 additions & 4 deletions packages/insomnia/src/ui/routes/auth.vaultKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,20 +174,22 @@ export const updateVaultSaltAction: ActionFunction = async () => {
};

export const clearVaultKeyAction: ActionFunction = async ({ request }) => {
const { organizations = [] } = await request.json();
const { organizations = [], sessionId: resetVaultClientSessionId } = await request.json();

const userSession = await sessionModel.getOrCreate();
const { vaultSalt, id: sessionId } = userSession;
const { id: sessionId } = userSession;
const { salt: newVaultSalt } = await insomniaFetch<{
salt?: string;
error?: string;
}>({
method: 'GET',
path: '/v1/user/vault',
sessionId,
});
}).catch(error => {
console.error(`failed to get vault salt ${error.toString()}`);
}) || {};
// User on other device has reset the vault key.
if (newVaultSalt && vaultSalt !== newVaultSalt) {
if (resetVaultClientSessionId !== sessionId) {
// remove all secret environment variables
await removeAllSecrets(organizations);
// Update vault salt and delelte vault key from session
Expand Down

0 comments on commit 1f9ea66

Please sign in to comment.