enzostvs HF Staff commited on
Commit
6ffacfe
·
1 Parent(s): 2009fd5

hf sign in

Browse files
app/login/callback/page.tsx CHANGED
@@ -1,3 +1,5 @@
 
 
1
  async function getAuth(code: string) {
2
  try {
3
  const REDIRECT_URI = `https://${process.env.SPACE_HOST}/login/callback`;
@@ -23,18 +25,15 @@ async function getAuth(code: string) {
23
  .clone()
24
  .json()
25
  .catch(() => ({}));
26
- const userRequest = await fetch("https://huggingface.co/oauth/userinfo", {
27
- method: "GET",
28
- headers: {
29
- Authorization: `Bearer ${response.access_token}`,
30
- },
 
31
  });
32
- const user = await userRequest
33
- .clone()
34
- .json()
35
- .catch(() => ({}));
36
- console.log(user);
37
- return user;
38
  } catch (error) {
39
  console.log("error", error);
40
  return null;
@@ -47,7 +46,6 @@ export default async function LoginCallback({
47
  searchParams: { [key: string]: string | string[] | undefined };
48
  }) {
49
  const profile = await getAuth(searchParams?.code as string);
50
- console.log(profile);
51
  return (
52
  <div className="pb-32 text-white">
53
  <p className="font-bold text-4xl text-white">LOGIN CALLBACK</p>
 
1
+ import { cookies } from "next/headers";
2
+
3
  async function getAuth(code: string) {
4
  try {
5
  const REDIRECT_URI = `https://${process.env.SPACE_HOST}/login/callback`;
 
25
  .clone()
26
  .json()
27
  .catch(() => ({}));
28
+
29
+ if (!response.access_token) {
30
+ return null;
31
+ }
32
+ cookies.set("access_token", response.access_token, {
33
+ expires: response.expires_in,
34
  });
35
+
36
+ return response;
 
 
 
 
37
  } catch (error) {
38
  console.log("error", error);
39
  return null;
 
46
  searchParams: { [key: string]: string | string[] | undefined };
47
  }) {
48
  const profile = await getAuth(searchParams?.code as string);
 
49
  return (
50
  <div className="pb-32 text-white">
51
  <p className="font-bold text-4xl text-white">LOGIN CALLBACK</p>
components/button/index.tsx CHANGED
@@ -15,7 +15,7 @@ export const Button: React.FC<Props> = ({
15
  return (
16
  <button
17
  className={classNames(
18
- "rounded-full px-6 py-3 font-semibold flex items-center justify-center gap-2.5 border-[2px] transition-all duration-200 max-w-max",
19
  {
20
  "bg-primary text-white border-primary": theme === "primary",
21
  "bg-white text-gray-900 border-white": theme === "white",
 
15
  return (
16
  <button
17
  className={classNames(
18
+ "rounded-full px-6 py-2.5 font-semibold flex items-center justify-center gap-2.5 border-[2px] transition-all duration-200 max-w-max",
19
  {
20
  "bg-primary text-white border-primary": theme === "primary",
21
  "bg-white text-gray-900 border-white": theme === "white",
components/main/index.tsx CHANGED
@@ -40,9 +40,13 @@ export const Main = () => {
40
  <div className="items-center justify-center lg:justify-end gap-5 w-full mt-6 lg:mt-0 hidden lg:flex">
41
  {categories.map(({ key, label, icon, isLogged }) =>
42
  isLogged && !user ? (
43
- <Button key={key} theme="white" onClick={openWindowLogin}>
44
- Sign in with Hugging Face
45
- </Button>
 
 
 
 
46
  ) : (
47
  <Button
48
  key={key}
 
40
  <div className="items-center justify-center lg:justify-end gap-5 w-full mt-6 lg:mt-0 hidden lg:flex">
41
  {categories.map(({ key, label, icon, isLogged }) =>
42
  isLogged && !user ? (
43
+ // <Button key={key} theme="white" onClick={openWindowLogin}>
44
+ // Sign in with Hugging Face
45
+ // </Button>
46
+ <img
47
+ src="https://huggingface.co/datasets/huggingface/badges/resolve/main/sign-in-with-huggingface-xl.svg"
48
+ onClick={openWindowLogin}
49
+ />
50
  ) : (
51
  <Button
52
  key={key}