forked from MergeFi/frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCallbackClient.tsx
More file actions
39 lines (35 loc) · 1.22 KB
/
Copy pathCallbackClient.tsx
File metadata and controls
39 lines (35 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
"use client";
import { useEffect, useState } from "react";
import { useRouter, useSearchParams } from "next/navigation";
import { useAuth } from "@/context/AuthContext";
export function CallbackClient() {
const router = useRouter();
const searchParams = useSearchParams();
const { login } = useAuth();
const [error, setError] = useState<string | null>(null);
useEffect(() => {
const token = searchParams.get("token");
if (!token) {
// eslint-disable-next-line react-hooks/set-state-in-effect
setError("No token was returned by GitHub sign-in.");
return;
}
login(token)
.then(() => router.replace("/dashboard/contributor"))
.catch(() => setError("Could not complete sign-in. Please try again."));
}, [searchParams, login, router]);
return (
<div className="mx-auto max-w-md px-6 py-24 text-center">
{error ? (
<>
<p className="font-medium text-rose-600">{error}</p>
<p className="mt-2 text-sm text-slate-500 dark:text-slate-400">
Make sure the mergefi-backend is running and reachable.
</p>
</>
) : (
<p className="text-slate-500 dark:text-slate-400">Finishing sign-in…</p>
)}
</div>
);
}