This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

feat: log user out on client create/update error

+82 -32
+30 -15
src/webapp/features/cards/lib/dal.ts
··· 1 - import { verifySessionOnClient } from '@/lib/auth/dal'; 1 + import { verifySessionOnClient, logoutUser } from '@/lib/auth/dal'; 2 2 import { createSembleClient } from '@/services/client.apiClient'; 3 3 import { CardSortField, SortOrder, UrlType } from '@semble/types'; 4 4 import { cache } from 'react'; ··· 51 51 const session = await verifySessionOnClient({ redirectOnFail: true }); 52 52 if (!session) throw new Error('No session found'); 53 53 const client = createSembleClient(); 54 - const response = await client.addUrlToLibrary({ 55 - url: url, 56 - note: note, 57 - collectionIds: collectionIds, 58 - viaCardId: viaCardId, 59 - }); 54 + 55 + try { 56 + const response = await client.addUrlToLibrary({ 57 + url: url, 58 + note: note, 59 + collectionIds: collectionIds, 60 + viaCardId: viaCardId, 61 + }); 60 62 61 - return response; 63 + return response; 64 + } catch (error) { 65 + await logoutUser(); 66 + } 62 67 }, 63 68 ); 64 69 ··· 96 101 const session = await verifySessionOnClient({ redirectOnFail: true }); 97 102 if (!session) throw new Error('No session found'); 98 103 const client = createSembleClient(); 99 - const response = await client.removeCardFromCollection({ 100 - cardId, 101 - collectionIds, 102 - }); 104 + 105 + try { 106 + const response = await client.removeCardFromCollection({ 107 + cardId, 108 + collectionIds, 109 + }); 103 110 104 - return response; 111 + return response; 112 + } catch (error) { 113 + await logoutUser(); 114 + } 105 115 }, 106 116 ); 107 117 ··· 109 119 const session = await verifySessionOnClient({ redirectOnFail: true }); 110 120 if (!session) throw new Error('No session found'); 111 121 const client = createSembleClient(); 112 - const response = await client.removeCardFromLibrary({ cardId }); 122 + 123 + try { 124 + const response = await client.removeCardFromLibrary({ cardId }); 113 125 114 - return response; 126 + return response; 127 + } catch (error) { 128 + await logoutUser(); 129 + } 115 130 }); 116 131 117 132 export const getLibrariesForCard = cache(async (cardId: string) => {
+8 -6
src/webapp/features/collections/components/createCollectionDrawer/CreateCollectionDrawer.tsx
··· 44 44 { 45 45 onSuccess: (newCollection) => { 46 46 props.onClose(); 47 - props.onCreate && 48 - props.onCreate({ 49 - id: newCollection.collectionId, 50 - name: form.getValues().name, 51 - cardCount: 0, 52 - }); 47 + if (newCollection) { 48 + props.onCreate && 49 + props.onCreate({ 50 + id: newCollection.collectionId, 51 + name: form.getValues().name, 52 + cardCount: 0, 53 + }); 54 + } 53 55 }, 54 56 onError: () => { 55 57 notifications.show({
+22 -7
src/webapp/features/collections/lib/dal.ts
··· 1 - import { verifySessionOnClient } from '@/lib/auth/dal'; 1 + import { logoutUser, verifySessionOnClient } from '@/lib/auth/dal'; 2 2 import { createSembleClient } from '@/services/client.apiClient'; 3 3 import { 4 4 CardSortField, ··· 107 107 const session = await verifySessionOnClient({ redirectOnFail: true }); 108 108 if (!session) throw new Error('No session found'); 109 109 const client = createSembleClient(); 110 - const response = await client.createCollection(newCollection); 110 + 111 + try { 112 + const response = await client.createCollection(newCollection); 111 113 112 - return response; 114 + return response; 115 + } catch (error) { 116 + await logoutUser(); 117 + } 113 118 }, 114 119 ); 115 120 ··· 117 122 const session = await verifySessionOnClient({ redirectOnFail: true }); 118 123 if (!session) throw new Error('No session found'); 119 124 const client = createSembleClient(); 120 - const response = await client.deleteCollection({ collectionId: id }); 125 + 126 + try { 127 + const response = await client.deleteCollection({ collectionId: id }); 121 128 122 - return response; 129 + return response; 130 + } catch (error) { 131 + await logoutUser(); 132 + } 123 133 }); 124 134 125 135 export const updateCollection = cache( ··· 132 142 const session = await verifySessionOnClient({ redirectOnFail: true }); 133 143 if (!session) throw new Error('No session found'); 134 144 const client = createSembleClient(); 135 - const response = await client.updateCollection(collection); 145 + 146 + try { 147 + const response = await client.updateCollection(collection); 136 148 137 - return response; 149 + return response; 150 + } catch (error) { 151 + await logoutUser(); 152 + } 138 153 }, 139 154 ); 140 155
+1 -1
src/webapp/features/collections/lib/mutations/useUpdateCollection.tsx
··· 15 15 return updateCollection(collection); 16 16 }, 17 17 18 - onSuccess: (variables) => { 18 + onSuccess: (_data, variables) => { 19 19 queryClient.invalidateQueries({ 20 20 queryKey: collectionKeys.collection(variables.collectionId), 21 21 });
+8 -3
src/webapp/features/notes/lib/dal.ts
··· 1 - import { verifySessionOnClient } from '@/lib/auth/dal'; 1 + import { logoutUser, verifySessionOnClient } from '@/lib/auth/dal'; 2 2 import { createSembleClient } from '@/services/client.apiClient'; 3 3 import { cache } from 'react'; 4 4 ··· 25 25 const session = await verifySessionOnClient({ redirectOnFail: true }); 26 26 if (!session) throw new Error('No session found'); 27 27 const client = createSembleClient(); 28 - const response = await client.updateNoteCard(note); 28 + 29 + try { 30 + const response = await client.updateNoteCard(note); 29 31 30 - return response; 32 + return response; 33 + } catch (error) { 34 + await logoutUser(); 35 + } 31 36 }, 32 37 );
+1
src/webapp/features/notes/lib/mutations/useUpdateNote.tsx
··· 14 14 }, 15 15 16 16 onSuccess: (data) => { 17 + if (!data) return; 17 18 queryClient.invalidateQueries({ queryKey: cardKeys.card(data.cardId) }); 18 19 queryClient.invalidateQueries({ queryKey: cardKeys.infinite() }); 19 20 queryClient.invalidateQueries({
+12
src/webapp/lib/auth/dal.ts
··· 1 1 import type { GetProfileResponse } from '@/api-client/ApiClient'; 2 2 import { cache } from 'react'; 3 + import { ClientCookieAuthService } from '@/services/auth/CookieAuthService.client'; 3 4 4 5 const appUrl = process.env.NEXT_PUBLIC_APP_URL || 'http://127.0.0.1:4000'; 5 6 ··· 48 49 return refreshPromise; 49 50 }, 50 51 ); 52 + 53 + /** 54 + * Logs out the current user by clearing tokens and redirecting to login 55 + * Can be called from both client and server contexts 56 + */ 57 + export const logoutUser = async (): Promise<void> => { 58 + await ClientCookieAuthService.clearTokens(); 59 + if (typeof window !== 'undefined') { 60 + window.location.href = '/login'; 61 + } 62 + };