jbilcke-hf HF staff commited on
Commit
b6516e1
1 Parent(s): 9009efd

let's make it sound less dramatic

Browse files
src/app/state/{userCurrentUser.ts → useCurrentUser.ts} RENAMED
@@ -100,25 +100,25 @@ export function useCurrentUser({
100
 
101
  // can be called many times, but won't do the API call if not necessary
102
  const main = async (isLoginRequired: boolean) => {
 
 
103
  try {
104
- // let's pirate hugging face! 🤗
105
- // @admins chill, it's not what you think, but more like a Next/React hack
106
- const hack = localStorage.getItem("aitube.at:login") || "{}"
107
- if (hack) {
108
- const hacked = JSON.parse(hack)
109
- localStorage.setItem("huggingface.co:oauth:nonce", hacked.nonce)
110
- localStorage.setItem("huggingface.co:oauth:code_verifier", hacked.codeVerifier)
111
- localStorage.removeItem("aitube.at:login")
112
- console.log("successfully hacked Hugging Face and removed traces of our deed 🤗")
113
- }
114
  } catch (err) {
115
- console.log("failed to hack Hugging Face! :sadface:")
116
  }
117
 
118
  console.log("useCurrentUser()")
119
  const searchParams = new URLSearchParams(window.location.search);
120
 
121
-
122
  console.log("debug:", {
123
  "window.location.search:": window.location.search,
124
  searchParams,
@@ -199,11 +199,15 @@ export function useCurrentUser({
199
  state: JSON.stringify({ redirectTo })
200
  })
201
 
202
- const nonce = localStorage.getItem("huggingface.co:oauth:nonce")
203
- const codeVerifier = localStorage.getItem("huggingface.co:oauth:code_verifier")
204
- const hack = JSON.stringify({ nonce, codeVerifier })
205
- console.log("hack:", hack)
206
- localStorage.setItem("aitube.at:login", hack)
 
 
 
 
207
 
208
  // should we open this in a new tab?
209
  window.location.href = oauthUrl
 
100
 
101
  // can be called many times, but won't do the API call if not necessary
102
  const main = async (isLoginRequired: boolean) => {
103
+
104
+ // DIY
105
  try {
106
+ localStorage.setItem(
107
+ "huggingface.co:oauth:nonce",
108
+ localStorage.getItem("aitube.at:oauth:nonce") || ""
109
+ )
110
+ localStorage.removeItem("aitube.co:oauth:code_verifier")
111
+ localStorage.setItem(
112
+ "huggingface.co:oauth:code_verifier",
113
+ localStorage.getItem("aitube.at:oauth:code_verifier") || ""
114
+ )
 
115
  } catch (err) {
116
+ console.log("no pending oauth flow to finish")
117
  }
118
 
119
  console.log("useCurrentUser()")
120
  const searchParams = new URLSearchParams(window.location.search);
121
 
 
122
  console.log("debug:", {
123
  "window.location.search:": window.location.search,
124
  searchParams,
 
199
  state: JSON.stringify({ redirectTo })
200
  })
201
 
202
+ // DIY
203
+ localStorage.setItem(
204
+ "aitube.at:oauth:nonce",
205
+ localStorage.getItem("huggingface.co:oauth:nonce") || ""
206
+ )
207
+ localStorage.setItem(
208
+ "huggingface.at:oauth:code_verifier",
209
+ localStorage.getItem("huggingface.co:oauth:code_verifier") || ""
210
+ )
211
 
212
  // should we open this in a new tab?
213
  window.location.href = oauthUrl
src/app/views/public-video-view/index.tsx CHANGED
@@ -28,7 +28,7 @@ import { Input } from "@/components/ui/input"
28
  import { localStorageKeys } from "@/app/state/localStorageKeys"
29
  import { defaultSettings } from "@/app/state/defaultSettings"
30
  import { getComments, submitComment } from "@/app/server/actions/comments"
31
- import { useCurrentUser } from "@/app/state/userCurrentUser"
32
  import { useLocalStorage } from "usehooks-ts"
33
 
34
  export function PublicVideoView() {
 
28
  import { localStorageKeys } from "@/app/state/localStorageKeys"
29
  import { defaultSettings } from "@/app/state/defaultSettings"
30
  import { getComments, submitComment } from "@/app/server/actions/comments"
31
+ import { useCurrentUser } from "@/app/state/useCurrentUser"
32
  import { useLocalStorage } from "usehooks-ts"
33
 
34
  export function PublicVideoView() {
src/app/views/user-account-view/index.tsx CHANGED
@@ -7,7 +7,7 @@ import { cn } from "@/lib/utils"
7
  import { ChannelList } from "@/app/interface/channel-list"
8
 
9
  import { getPrivateChannels } from "@/app/server/actions/ai-tube-hf/getPrivateChannels"
10
- import { useCurrentUser } from "@/app/state/userCurrentUser"
11
  import { Button } from "@/components/ui/button"
12
  import { Input } from "@/components/ui/input"
13
 
 
7
  import { ChannelList } from "@/app/interface/channel-list"
8
 
9
  import { getPrivateChannels } from "@/app/server/actions/ai-tube-hf/getPrivateChannels"
10
+ import { useCurrentUser } from "@/app/state/useCurrentUser"
11
  import { Button } from "@/components/ui/button"
12
  import { Input } from "@/components/ui/input"
13