jbilcke-hf HF staff commited on
Commit
3824e7f
1 Parent(s): 16891a6

try to fix the login

Browse files
src/app/state/userCurrentUser.ts CHANGED
@@ -19,7 +19,7 @@ export function useCurrentUser({
19
  isLoginRequired?: boolean
20
  } = {}): {
21
  user?: UserInfo
22
- login: () => void
23
  checkSession: (isLoginRequired: boolean) => Promise<UserInfo | undefined>
24
  apiKey: string
25
  oauthResult?: OAuthResult
@@ -130,7 +130,13 @@ export function useCurrentUser({
130
  }, [isLoginRequired, huggingfaceApiKey, huggingfaceTemporaryApiKey, userId])
131
 
132
 
133
- const login = async () => {
 
 
 
 
 
 
134
  const oauthUrl = await oauthLoginUrl({
135
  /**
136
  * OAuth client ID.
@@ -165,7 +171,7 @@ export function useCurrentUser({
165
  *
166
  * For Developer Applications, you can add any URL you want to the list of allowed redirect URIs at https://huggingface.co/settings/connected-applications.
167
  */
168
- redirectUrl: "https://jbilcke-hf-ai-tube.hf.space",
169
 
170
  /**
171
  * State to pass to the OAuth provider, which will be returned in the call to `oauthLogin` after the redirect.
 
19
  isLoginRequired?: boolean
20
  } = {}): {
21
  user?: UserInfo
22
+ login: (redirectUrl?: string) => void
23
  checkSession: (isLoginRequired: boolean) => Promise<UserInfo | undefined>
24
  apiKey: string
25
  oauthResult?: OAuthResult
 
130
  }, [isLoginRequired, huggingfaceApiKey, huggingfaceTemporaryApiKey, userId])
131
 
132
 
133
+ const login = async (redirectUrlOrPath: string = "") => {
134
+
135
+ const redirectUrl = redirectUrlOrPath[0] === "/"
136
+ ? `https://jbilcke-hf-ai-tube.hf.space${redirectUrlOrPath || ""}`
137
+ : redirectUrlOrPath ? redirectUrlOrPath
138
+ : ""
139
+
140
  const oauthUrl = await oauthLoginUrl({
141
  /**
142
  * OAuth client ID.
 
171
  *
172
  * For Developer Applications, you can add any URL you want to the list of allowed redirect URIs at https://huggingface.co/settings/connected-applications.
173
  */
174
+ redirectUrl,
175
 
176
  /**
177
  * State to pass to the OAuth provider, which will be returned in the call to `oauthLogin` after the redirect.
src/app/views/user-account-view/index.tsx CHANGED
@@ -64,7 +64,7 @@ export function UserAccountView() {
64
  {apiKey ?
65
  <div className="flex flex-col space-y-4">
66
  <h2 className="text-3xl font-bold">@{user?.userName} channels</h2>
67
- <p>Don&apos;t see your channel? try to <Button onClick={login}>synchronize</Button> again.</p>
68
 
69
  {userChannels?.length ? <ChannelList
70
  layout="grid"
@@ -82,7 +82,7 @@ export function UserAccountView() {
82
  }}
83
  />
84
  : isLoaded ? null : <p>Loading channels owned by @{user?.userName}..</p>}
85
- </div> : <p>To create a channel, comment or like a video please <Button onClick={login}>Login with Hugging Face</Button>.</p>}
86
  </div>
87
  )
88
  }
 
64
  {apiKey ?
65
  <div className="flex flex-col space-y-4">
66
  <h2 className="text-3xl font-bold">@{user?.userName} channels</h2>
67
+ <p>Don&apos;t see your channel? try to <Button onClick={() => login("/account")}>synchronize</Button> again.</p>
68
 
69
  {userChannels?.length ? <ChannelList
70
  layout="grid"
 
82
  }}
83
  />
84
  : isLoaded ? null : <p>Loading channels owned by @{user?.userName}..</p>}
85
+ </div> : <p>To create a channel, comment or like a video please <Button onClick={() => login("/account")}>Login with Hugging Face</Button>.</p>}
86
  </div>
87
  )
88
  }