Spaces:
Running
Running
test login
Browse files
app/api/auth/route.ts
CHANGED
|
@@ -2,6 +2,8 @@ import { NextRequest, NextResponse } from "next/server";
|
|
| 2 |
// import { cookies } from "next/headers";
|
| 3 |
// import MY_TOKEN_KEY from "@/lib/get-cookie-name";
|
| 4 |
|
|
|
|
|
|
|
| 5 |
export async function GET() {
|
| 6 |
const redirect_uri = process.env.REDIRECT_URI;
|
| 7 |
const loginRedirectUrl = `https://huggingface.co/oauth/authorize?client_id=${process.env.HUGGINGFACE_CLIENT_ID}&redirect_uri=${redirect_uri}&response_type=code&scope=openid%20profile%20write-repos%20manage-repos%20inference-api&prompt=consent&state=1234567890`;
|
|
|
|
| 2 |
// import { cookies } from "next/headers";
|
| 3 |
// import MY_TOKEN_KEY from "@/lib/get-cookie-name";
|
| 4 |
|
| 5 |
+
// TODO refacto to do not use the window.postMessage, doesn't work with iFrame
|
| 6 |
+
|
| 7 |
export async function GET() {
|
| 8 |
const redirect_uri = process.env.REDIRECT_URI;
|
| 9 |
const loginRedirectUrl = `https://huggingface.co/oauth/authorize?client_id=${process.env.HUGGINGFACE_CLIENT_ID}&redirect_uri=${redirect_uri}&response_type=code&scope=openid%20profile%20write-repos%20manage-repos%20inference-api&prompt=consent&state=1234567890`;
|
app/auth/callback/page.tsx
CHANGED
|
@@ -13,6 +13,7 @@ export default function AuthCallback({
|
|
| 13 |
|
| 14 |
const { postMessage } = useBroadcastChannel("auth", () => {});
|
| 15 |
useMount(() => {
|
|
|
|
| 16 |
if (code) {
|
| 17 |
postMessage({
|
| 18 |
code: code,
|
|
|
|
| 13 |
|
| 14 |
const { postMessage } = useBroadcastChannel("auth", () => {});
|
| 15 |
useMount(() => {
|
| 16 |
+
console.log("AuthCallback mounted", code);
|
| 17 |
if (code) {
|
| 18 |
postMessage({
|
| 19 |
code: code,
|
components/contexts/app-context.tsx
CHANGED
|
@@ -41,6 +41,7 @@ export default function AppContext({
|
|
| 41 |
const events: any = {};
|
| 42 |
|
| 43 |
useBroadcastChannel("auth", (message) => {
|
|
|
|
| 44 |
if (pathname.includes("/auth/callback")) return;
|
| 45 |
|
| 46 |
if (!message.code) return;
|
|
|
|
| 41 |
const events: any = {};
|
| 42 |
|
| 43 |
useBroadcastChannel("auth", (message) => {
|
| 44 |
+
console.log("Received message from auth channel:", message);
|
| 45 |
if (pathname.includes("/auth/callback")) return;
|
| 46 |
|
| 47 |
if (!message.code) return;
|