Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Commit
•
f021dad
1
Parent(s):
70b0c73
..
Browse files- src/app/state/useCurrentUser.ts +43 -24
src/app/state/useCurrentUser.ts
CHANGED
@@ -99,7 +99,29 @@ export function useCurrentUser({
|
|
99 |
}
|
100 |
|
101 |
// can be called many times, but won't do the API call if not necessary
|
102 |
-
const main =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
|
104 |
// DIY
|
105 |
try {
|
@@ -125,33 +147,30 @@ export function useCurrentUser({
|
|
125 |
searchParams,
|
126 |
})
|
127 |
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
137 |
}
|
138 |
-
} catch (err) {
|
139 |
-
}
|
140 |
-
|
141 |
-
// already logged-in, no need to spend an API call
|
142 |
-
// although it is worth noting that the API token might be expired at this stage
|
143 |
-
if (userId) {
|
144 |
-
console.log("we are already logged-in")
|
145 |
-
return
|
146 |
}
|
147 |
|
148 |
-
|
149 |
-
|
150 |
-
|
|
|
151 |
|
152 |
-
useEffect(() => {
|
153 |
-
startTransition(async () => { await main(isLoginRequired) })
|
154 |
-
}, [isLoginRequired, huggingfaceApiKey, huggingfaceTemporaryApiKey, userId])
|
155 |
|
156 |
|
157 |
const login = async (
|
|
|
99 |
}
|
100 |
|
101 |
// can be called many times, but won't do the API call if not necessary
|
102 |
+
const main = (isLoginRequired: boolean) => {
|
103 |
+
// already logged-in, no need to spend an API call
|
104 |
+
// although it is worth noting that the API token might be expired at this stage
|
105 |
+
if (userId) {
|
106 |
+
console.log("we are already logged-in")
|
107 |
+
return
|
108 |
+
}
|
109 |
+
|
110 |
+
startTransition(async () => {
|
111 |
+
|
112 |
+
console.log("useCurrentUser(): yes, we need to call synchronizeSession()")
|
113 |
+
|
114 |
+
await checkSession(isLoginRequired)
|
115 |
+
})
|
116 |
+
}
|
117 |
+
|
118 |
+
useEffect(() => {
|
119 |
+
main(isLoginRequired)
|
120 |
+
}, [isLoginRequired, huggingfaceApiKey, huggingfaceTemporaryApiKey, userId])
|
121 |
+
|
122 |
+
|
123 |
+
|
124 |
+
useEffect(() => {
|
125 |
|
126 |
// DIY
|
127 |
try {
|
|
|
147 |
searchParams,
|
148 |
})
|
149 |
|
150 |
+
const fn = async () => {
|
151 |
+
try {
|
152 |
+
const res = await oauthHandleRedirectIfPresent()
|
153 |
+
console.log("result of oauthHandleRedirectIfPresent:", res)
|
154 |
+
if (res) {
|
155 |
+
console.log("oauthHandleRedirectIfPresent returned something!", res)
|
156 |
+
setOauthResult(res)
|
157 |
+
setHuggingfaceTemporaryApiKey(res.accessToken)
|
158 |
+
startTransition(async () => {
|
159 |
+
console.log("TODO julian do something, eg. reload the page, remove the things in the URL etc")
|
160 |
+
// await checkSession(isLoginRequired)
|
161 |
+
})
|
162 |
+
}
|
163 |
+
|
164 |
+
} catch (err) {
|
165 |
+
console.error(err)
|
166 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
167 |
}
|
168 |
|
169 |
+
fn()
|
170 |
+
}, [isLoginRequired])
|
171 |
+
|
172 |
+
|
173 |
|
|
|
|
|
|
|
174 |
|
175 |
|
176 |
const login = async (
|