Github access test
This commit is contained in:
@@ -19,6 +19,9 @@ import Link from "next/link";
|
|||||||
import { getLiveNodes } from "@/core/node";
|
import { getLiveNodes } from "@/core/node";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { Node, NodeLiveData } from "@/lib/types";
|
import { Node, NodeLiveData } from "@/lib/types";
|
||||||
|
import axios from "axios";
|
||||||
|
import Cookies from "js-cookie";
|
||||||
|
import { getSession } from "@/core/auth/session";
|
||||||
|
|
||||||
const recentDeployments = [
|
const recentDeployments = [
|
||||||
{
|
{
|
||||||
@@ -99,6 +102,29 @@ export default function OverviewPage() {
|
|||||||
};
|
};
|
||||||
fetchNodes();
|
fetchNodes();
|
||||||
const interval = setInterval(fetchNodes, 3000);
|
const interval = setInterval(fetchNodes, 3000);
|
||||||
|
|
||||||
|
const test = async () => {
|
||||||
|
const sessionToken = await getSession();
|
||||||
|
console.log(sessionToken);
|
||||||
|
// console.log(
|
||||||
|
// (
|
||||||
|
// await axios.get("https://api.github.com/user/repos", {
|
||||||
|
// headers: { Authorization: `Bearer ${sessionToken}` },
|
||||||
|
// })
|
||||||
|
// ).data
|
||||||
|
// );
|
||||||
|
|
||||||
|
// console.log(
|
||||||
|
// (
|
||||||
|
// await axios.get("https://api.github.com/orgs/orus-dev/repos", {
|
||||||
|
// headers: { Authorization: `Bearer ${sessionToken}` },
|
||||||
|
// })
|
||||||
|
// ).data
|
||||||
|
// );
|
||||||
|
};
|
||||||
|
|
||||||
|
test();
|
||||||
|
|
||||||
return () => clearInterval(interval);
|
return () => clearInterval(interval);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,14 @@
|
|||||||
import { getIronSession } from "iron-session";
|
"use server";
|
||||||
|
import { cookies } from "next/headers";
|
||||||
|
import { redirect } from "next/navigation";
|
||||||
|
|
||||||
export const session = getIronSession({
|
export async function getSession() {
|
||||||
password: process.env.SESSION_PASSWORD!,
|
const c = await cookies();
|
||||||
cookieName: "nextjs_oauth_session",
|
const accessToken = c.get("github_access")?.value;
|
||||||
secure: process.env.NODE_ENV === "production",
|
|
||||||
});
|
if (!accessToken) {
|
||||||
|
redirect("/");
|
||||||
|
}
|
||||||
|
|
||||||
|
return accessToken;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user