alpha
Login
or
Join now
atpota.to
/
cred.blue
Star
0
Fork
0
Atom
Configure Feed
Issues
Pull Requests
Commits
Tags
Feed URL
Select the types of activity you want to include in your feed.
This repository has no description
Star
0
Fork
0
Atom
Configure Feed
Issues
Pull Requests
Commits
Tags
Feed URL
Select the types of activity you want to include in your feed.
Overview
Issues
Pulls
Pipelines
switch userprofile save endpoint
author
damedotblog
date
1 year ago
(Feb 24, 2025, 11:41 AM -0500)
commit
beea8eb7
beea8eb735824497c94bf2c4c5d316f76b9adc45
parent
faa5a172
faa5a1726a447f42ac6bc3b1097140a36f7d7166
+18
-60
1 changed file
Expand all
Collapse all
Unified
Split
src
components
UserProfile
UserProfile.js
+18
-60
src/components/UserProfile/UserProfile.js
Reviewed
···
78
78
const layouts = createLayouts();
79
79
80
80
// Memoized save function with debouncing
81
81
+
// Create a function to save user data securely through the backend
81
82
const createDebouncedSave = () => {
82
83
let timeout;
83
84
return async (userData) => {
84
85
if (timeout) clearTimeout(timeout);
85
86
timeout = setTimeout(async () => {
86
87
try {
87
87
-
const { error } = await supabase
88
88
-
.from('user_scores')
89
89
-
.upsert({
90
90
-
// Basic profile info
91
91
-
handle: userData.handle,
92
92
-
display_name: userData.displayName,
93
93
-
did: userData.did,
94
94
-
profile_edited_date: userData.profileEditedDate,
95
95
-
profile_completion: userData.profileCompletion,
96
96
-
97
97
-
// Score fields
98
98
-
combined_score: userData.combinedScore,
99
99
-
bluesky_score: userData.blueskyScore,
100
100
-
atproto_score: userData.atprotoScore,
101
101
-
102
102
-
// Activity metrics
103
103
-
activity_status: userData.activityAll.activityStatus,
104
104
-
bsky_activity_status: userData.activityAll.bskyActivityStatus,
105
105
-
atproto_activity_status: userData.activityAll.atprotoActivityStatus,
106
106
-
total_collections: userData.activityAll.totalCollections,
107
107
-
total_bsky_collections: userData.activityAll.totalBskyCollections,
108
108
-
total_non_bsky_collections: userData.activityAll.totalNonBskyCollections,
109
109
-
total_records: userData.activityAll.totalRecords,
110
110
-
total_bsky_records: userData.activityAll.totalBskyRecords,
111
111
-
total_non_bsky_records: userData.activityAll.totalNonBskyRecords,
112
112
-
plc_operations: userData.activityAll.plcOperations,
113
113
-
blobs_count: userData.activityAll.blobsCount,
114
114
-
115
115
-
// Store category data as JSONB
116
116
-
blueskycategories: userData.blueskyCategories,
117
117
-
atprotocategories: userData.atprotoCategories,
118
118
-
119
119
-
// Metadata fields
120
120
-
service_endpoint: userData.serviceEndpoint,
121
121
-
pds_type: userData.pdsType,
122
122
-
created_at: userData.createdAt,
123
123
-
age_in_days: userData.ageInDays,
124
124
-
age_percentage: userData.agePercentage,
125
125
-
followers_count: userData.followersCount,
126
126
-
follows_count: userData.followsCount,
127
127
-
posts_count: userData.postsCount,
128
128
-
rotation_keys: userData.rotationKeys,
129
129
-
era: userData.era,
130
130
-
posting_style: userData.postingStyle,
131
131
-
social_status: userData.socialStatus,
132
132
-
133
133
-
// Store complex metrics as JSONB
134
134
-
engagement_metrics: userData.engagementMetrics,
135
135
-
weekly_activity: userData.weeklyActivity,
136
136
-
137
137
-
// Store full profile data
138
138
-
profile_data: userData.profile,
139
139
-
140
140
-
// Update timestamp
141
141
-
last_checked_at: new Date()
142
142
-
}, {
143
143
-
onConflict: 'handle'
144
144
-
});
145
145
-
146
146
-
if (error) throw error;
88
88
+
// Call the backend endpoint instead of directly writing to Supabase
89
89
+
const response = await fetch('https://cred.blue/api/save-user-data', {
90
90
+
method: 'POST',
91
91
+
headers: {
92
92
+
'Content-Type': 'application/json'
93
93
+
},
94
94
+
body: JSON.stringify(userData)
95
95
+
});
96
96
+
97
97
+
if (!response.ok) {
98
98
+
const errorData = await response.json();
99
99
+
throw new Error(errorData.error || 'Failed to save user data');
100
100
+
}
101
101
+
102
102
+
// Optional: Handle successful save response
103
103
+
const result = await response.json();
104
104
+
console.log('User data saved successfully:', result);
147
105
} catch (error) {
148
106
console.error('Error saving user data:', error);
149
107
}