Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions gateway/src/api/oauth/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,12 @@ impl OauthHandler for GithubOauthService {
.send()
.await
.unwrap();
// tracing::debug!("user_resp: {:?}", resp.text().await.unwrap());
let user_info = resp.json::<GitHubUserJson>().await.unwrap();
let mut user_info = GitHubUserJson::default();
if resp.status().is_success() {
user_info = resp.json::<GitHubUserJson>().await.unwrap();
} else {
tracing::error!("github:user_info:err {:?}", resp.text().await.unwrap());
}
Ok(user_info)
}
}
2 changes: 1 addition & 1 deletion gateway/src/api/oauth/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub struct GitHubAccessTokenJson {
pub token_type: String,
}

#[derive(Serialize, Deserialize, Clone, Debug)]
#[derive(Serialize, Deserialize, Clone, Debug, Default)]
pub struct GitHubUserJson {
pub login: String,
pub id: u32,
Expand Down
1 change: 0 additions & 1 deletion lunar/.env.local
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
RELAY_API_URL=http://34.84.172.121
NEXT_PUBLIC_API_URL=http://localhost:8000
NEXT_PUBLIC_CALLBACK_URL=http://localhost:3000/auth/github/callback
26 changes: 6 additions & 20 deletions lunar/src/app/application-layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ import {
TicketIcon,
} from '@heroicons/react/20/solid'
import { usePathname } from 'next/navigation'
import { useUser } from '@/app/api/fetcher';
import { Skeleton } from "antd";
import { Button } from '@/components/catalyst/button'
import { useState, useEffect } from 'react'

function AccountDropdownMenu({ anchor }: { anchor: 'top start' | 'bottom end' }) {
Expand Down Expand Up @@ -86,19 +83,15 @@ export function ApplicationLayout({
}
}, [])

const { user, isLoading, isError } = useUser(token);
if (isLoading) return <Skeleton />;
// const { user, isLoading, isError } = useUser(token);
// if (isLoading) return <Skeleton />;

return (
<SidebarLayout
navbar={
<Navbar>
<NavbarSpacer />
{
!token &&
<Button href="/login">Login</Button>
}
{
{/* {
token &&
<NavbarSection>
<Dropdown>
Expand All @@ -108,9 +101,7 @@ export function ApplicationLayout({
<AccountDropdownMenu anchor="bottom end" />
</Dropdown>
</NavbarSection>

}

} */}
</Navbar>
}
sidebar={
Expand Down Expand Up @@ -183,7 +174,7 @@ export function ApplicationLayout({
</SidebarBody>


<SidebarFooter className="max-lg:hidden">
{/* <SidebarFooter className="max-lg:hidden">
{token &&
<Dropdown>
<DropdownButton as={SidebarItem}>
Expand All @@ -201,12 +192,7 @@ export function ApplicationLayout({
<AccountDropdownMenu anchor="top start" />
</Dropdown>
}
{
!token &&
<Button href="/login">Login</Button>
}

</SidebarFooter>
</SidebarFooter> */}
</Sidebar>
}
>
Expand Down
21 changes: 0 additions & 21 deletions lunar/src/app/auth/github/callback/page.tsx

This file was deleted.

3 changes: 2 additions & 1 deletion moon/.env.local
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
NEXT_MEGA_API_URL=http://localhost:8000
NEXT_PUBLIC_API_URL=http://localhost:8000
NEXT_PUBLIC_CALLBACK_URL=http://localhost:3000/auth/github/callback
2 changes: 1 addition & 1 deletion moon/.env.production
Original file line number Diff line number Diff line change
@@ -1 +1 @@
NEXT_MEGA_API_URL=http://mega.api.com
NEXT_PUBLIC_API_URL=http://mega.api.com
4 changes: 2 additions & 2 deletions moon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
"react-markdown": "^9.0.1"
},
"devDependencies": {
"@types/node": "^20",
"@types/node": "^22",
"@types/react": "^18",
"@types/react-dom": "^18",
"autoprefixer": "^10.4.16",
"eslint": "^8",
"eslint": "^9.8",
"eslint-config-next": "14.0.3",
"postcss": "^8.4.31",
"typescript": "^5"
Expand Down
27 changes: 27 additions & 0 deletions moon/src/app/actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use server'

import { cookies } from 'next/headers'
import { redirect } from 'next/navigation';

export async function handleLogin(sessionData) {
const encryptedSessionData = encrypt(sessionData) // Encrypt your session data
cookies().set('access_token', encryptedSessionData, {
httpOnly: true,
secure: process.env.NODE_ENV === 'production',
maxAge: 60 * 60 * 24 * 7, // One week
path: '/',
})
redirect('/')
// Redirect or handle the response after setting the cookie
}

export async function get_access_token() {
const cookieStore = cookies()
const token = cookieStore.get('access_token')
return token
}

// TODO encrypt access_token
function encrypt(sessionData) {
return sessionData
}
23 changes: 23 additions & 0 deletions moon/src/app/api/auth/github/user/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// import { type NextRequest } from 'next/server'

import { cookies } from "next/headers";

export const revalidate = 0

const endpoint = process.env.NEXT_PUBLIC_API_URL;

export async function GET(request: Request) {
const cookieStore = cookies();
const access_token = cookieStore.get('access_token');

const res = await fetch(`${endpoint}/auth/github/user`, {
headers: {
'Authorization': `Bearer ${access_token?.value}`,
'Content-Type': 'application/json',
},
})

const data = await res.json()

return Response.json({ data })
}
2 changes: 1 addition & 1 deletion moon/src/app/api/blob/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { type NextRequest } from 'next/server'
export const dynamic = 'force-dynamic' // defaults to auto
export const revalidate = 0

const endpoint = process.env.NEXT_MEGA_API_URL;
const endpoint = process.env.NEXT_PUBLIC_API_URL;

export async function GET(request: NextRequest) {
const searchParams = request.nextUrl.searchParams
Expand Down
2 changes: 1 addition & 1 deletion moon/src/app/api/mr/[id]/detail/route.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const dynamic = 'force-dynamic' // defaults to auto
export const revalidate = 0

const endpoint = process.env.NEXT_MEGA_API_URL;
const endpoint = process.env.NEXT_PUBLIC_API_URL;

export async function GET(request: Request, { params }: { params: { id: string } }) {
const res = await fetch(`${endpoint}/api/v1/mr/${params.id}/detail`, {
Expand Down
2 changes: 1 addition & 1 deletion moon/src/app/api/mr/[id]/files/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const dynamic = 'force-dynamic' // defaults to auto

const endpoint = process.env.NEXT_MEGA_API_URL;
const endpoint = process.env.NEXT_PUBLIC_API_URL;

export async function GET(request: Request, { params }: { params: { id: string } }) {
const res = await fetch(`${endpoint}/api/v1/mr/${params.id}/files`, {
Expand Down
2 changes: 1 addition & 1 deletion moon/src/app/api/mr/[id]/merge/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const dynamic = 'force-dynamic' // defaults to auto

const endpoint = process.env.NEXT_MEGA_API_URL;
const endpoint = process.env.NEXT_PUBLIC_API_URL;


export async function POST(request: Request, { params }: { params: { id: string } }) {
Expand Down
2 changes: 1 addition & 1 deletion moon/src/app/api/mr/list/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export const revalidate = 0

import { type NextRequest } from 'next/server'

const endpoint = process.env.NEXT_MEGA_API_URL;
const endpoint = process.env.NEXT_PUBLIC_API_URL;

export async function GET(request: NextRequest) {
const searchParams = request.nextUrl.searchParams
Expand Down
2 changes: 1 addition & 1 deletion moon/src/app/api/tree/commit-info/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { type NextRequest } from 'next/server'
export const dynamic = 'force-dynamic' // defaults to auto
export const revalidate = 0

const endpoint = process.env.NEXT_MEGA_API_URL;
const endpoint = process.env.NEXT_PUBLIC_API_URL;

export async function GET(request: NextRequest) {
const searchParams = request.nextUrl.searchParams
Expand Down
2 changes: 1 addition & 1 deletion moon/src/app/api/tree/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export const revalidate = 0

export const dynamic = 'force-dynamic' // defaults to auto

const endpoint = process.env.NEXT_MEGA_API_URL;
const endpoint = process.env.NEXT_PUBLIC_API_URL;

export async function GET(request: NextRequest) {
const searchParams = request.nextUrl.searchParams
Expand Down
92 changes: 69 additions & 23 deletions moon/src/app/application-layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ import {
Square2StackIcon,
TicketIcon,
} from '@heroicons/react/20/solid'
import { Button } from '@/components/catalyst/button'
import { useState, useEffect } from 'react'
import { get_access_token } from '@/app/actions'
import { usePathname } from 'next/navigation'

function AccountDropdownMenu({ anchor }: { anchor: 'top start' | 'bottom end' }) {
Expand Down Expand Up @@ -67,28 +70,64 @@ function AccountDropdownMenu({ anchor }: { anchor: 'top start' | 'bottom end' })
)
}

interface User {
avatar_url: string;
login: string;
id: number;
email: string;
}

export function ApplicationLayout({
// events,
children,
}: {
// events: Awaited<ReturnType<typeof getEvents>>
children: React.ReactNode
}) {
let pathname = usePathname()
const [token, setToken] = useState("");
const [user, setUser] = useState<User | null>(null);
useEffect(() => {
fetch_token()
async function fetch_token() {
let res = await get_access_token();
if (res?.value) {
let token_value = res?.value;
setToken(token_value)
}
}
}, [])

useEffect(() => {
if (token) {
fetchMessage();
}
async function fetchMessage() {
const response = await fetch('http://localhost:3000/api/auth/github/user');
const user = await response.json();
setUser(user.data);
}
}, [token])

return (
<SidebarLayout
navbar={
<Navbar>
<NavbarSpacer />
<NavbarSection>
<Dropdown>
<DropdownButton as={NavbarItem}>
<Avatar src="/images/megaLogo.png" />
</DropdownButton>
<AccountDropdownMenu anchor="bottom end" />
</Dropdown>
</NavbarSection>
{
!user &&
<Button href="/login">Login</Button>
}
{
user &&
<NavbarSection>
<Dropdown>
<DropdownButton as={NavbarItem}>
<Avatar src={"" || user.avatar_url} />
</DropdownButton>
<AccountDropdownMenu anchor="bottom end" />
</Dropdown>
</NavbarSection>
}

</Navbar>
}
sidebar={
Expand Down Expand Up @@ -157,21 +196,27 @@ export function ApplicationLayout({
</SidebarBody>

<SidebarFooter className="max-lg:hidden">
<Dropdown>
<DropdownButton as={SidebarItem}>
<span className="flex min-w-0 items-center gap-3">
<Avatar slot="icon" initials="AD" className="size-10 bg-purple-500 text-white" />
<span className="min-w-0">
<span className="block truncate text-sm/5 font-medium text-zinc-950 dark:text-white">Admin</span>
<span className="block truncate text-xs/5 font-normal text-zinc-500 dark:text-zinc-400">
Admin@mega.com
{user &&
<Dropdown>
<DropdownButton as={SidebarItem}>
<span className="flex min-w-0 items-center gap-3">
<Avatar src={"" || user.avatar_url} slot="icon" initials="ME" className="size-10 bg-purple-500 text-white" />
<span className="min-w-0">
<span className="block truncate text-sm/5 font-medium text-zinc-950 dark:text-white">{user.login}</span>
<span className="block truncate text-xs/5 font-normal text-zinc-500 dark:text-zinc-400">
{user.email}
</span>
</span>
</span>
</span>
<ChevronUpIcon />
</DropdownButton>
<AccountDropdownMenu anchor="top start" />
</Dropdown>
<ChevronUpIcon />
</DropdownButton>
<AccountDropdownMenu anchor="top start" />
</Dropdown>
}
{
!user &&
<Button href="/login">Login</Button>
}
</SidebarFooter>
</Sidebar>
}
Expand All @@ -180,3 +225,4 @@ export function ApplicationLayout({
</SidebarLayout>
)
}

Loading