tfrere HF Staff Cursor commited on
Commit
a7e92df
·
1 Parent(s): 0fe543d

feat: use OAuth Bearer token with write-discussions scope for likes

Browse files

HF team confirmed the like endpoint accepts OAuth tokens. Switch back
to Bearer token auth (instead of credentials:'include') and add the
write-discussions scope which should cover like permissions.

Co-authored-by: Cursor <cursoragent@cursor.com>

Files changed (2) hide show
  1. README.md +2 -0
  2. src/context/AuthContext.jsx +6 -4
README.md CHANGED
@@ -6,6 +6,8 @@ colorTo: purple
6
  sdk: docker
7
  pinned: true
8
  hf_oauth: true
 
 
9
  thumbnail: >-
10
  https://cdn-uploads.huggingface.co/production/uploads/671faa3a541a76b548647676/XWNDlOu0R4fHXR0kCW3Wd.png
11
  short_description: All about Reachy Mini, from building to getting started
 
6
  sdk: docker
7
  pinned: true
8
  hf_oauth: true
9
+ hf_oauth_scopes:
10
+ - write-discussions
11
  thumbnail: >-
12
  https://cdn-uploads.huggingface.co/production/uploads/671faa3a541a76b548647676/XWNDlOu0R4fHXR0kCW3Wd.png
13
  short_description: All about Reachy Mini, from building to getting started
src/context/AuthContext.jsx CHANGED
@@ -65,11 +65,12 @@ export function AuthProvider({ children }) {
65
  // Check if user just completed OAuth redirect
66
  const oauthResult = await oauthHandleRedirectIfPresent();
67
  if (oauthResult) {
68
- const { userInfo } = oauthResult;
69
  const userData = {
70
  name: userInfo.name,
71
  preferredUsername: userInfo.preferred_username || userInfo.name,
72
  avatarUrl: userInfo.picture,
 
73
  };
74
  setUser(userData);
75
 
@@ -125,8 +126,7 @@ export function AuthProvider({ children }) {
125
 
126
  /**
127
  * Toggle like/unlike with optimistic update.
128
- * Uses credentials: 'include' to send HF session cookies — this works when
129
- * the page is served from huggingface.co (same-origin with the API).
130
  */
131
  const toggleLike = useCallback(
132
  async (spaceId) => {
@@ -159,7 +159,9 @@ export function AuthProvider({ children }) {
159
  try {
160
  const response = await fetch(`${HF_API}/api/spaces/${spaceId}/like`, {
161
  method,
162
- credentials: 'include',
 
 
163
  });
164
 
165
  if (!response.ok) {
 
65
  // Check if user just completed OAuth redirect
66
  const oauthResult = await oauthHandleRedirectIfPresent();
67
  if (oauthResult) {
68
+ const { accessToken, userInfo } = oauthResult;
69
  const userData = {
70
  name: userInfo.name,
71
  preferredUsername: userInfo.preferred_username || userInfo.name,
72
  avatarUrl: userInfo.picture,
73
+ accessToken: accessToken,
74
  };
75
  setUser(userData);
76
 
 
126
 
127
  /**
128
  * Toggle like/unlike with optimistic update.
129
+ * Uses OAuth Bearer token (requires write-discussions scope).
 
130
  */
131
  const toggleLike = useCallback(
132
  async (spaceId) => {
 
159
  try {
160
  const response = await fetch(`${HF_API}/api/spaces/${spaceId}/like`, {
161
  method,
162
+ headers: {
163
+ Authorization: `Bearer ${user.accessToken}`,
164
+ },
165
  });
166
 
167
  if (!response.ok) {