-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from badgeteam/feature/jwt
Send JWT token to server
- Loading branch information
Showing
16 changed files
with
153 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,22 @@ | ||
"use server"; | ||
|
||
import { GetAppsParams } from "@/badgehub-api-client/generated/models"; | ||
import { | ||
getDevices, | ||
getCategories, | ||
getApps, | ||
getCategories, | ||
getDevices, | ||
} from "@/badgehub-api-client/generated/swagger/public/public"; | ||
|
||
export async function getAppData(searchParams: GetAppsParams) { | ||
return Promise.all([getApps(searchParams), getCategories(), getDevices()]); | ||
export async function getAppData(searchParams: GetAppsParams, token: string) { | ||
const headers = new Headers({ | ||
Authorization: `Bearer ${token}`, | ||
}); | ||
const options: RequestInit = { | ||
headers, | ||
}; | ||
return Promise.all([ | ||
getApps(searchParams, options), | ||
getCategories(options), | ||
getDevices(options), | ||
]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,20 @@ | ||
import { ReactNode } from "react"; | ||
"use client"; | ||
|
||
import { SessionProvider } from "next-auth/react"; | ||
import styles from "./layout.module.css"; | ||
import { ReactNode } from "react"; | ||
|
||
type AppsListingLayoutProps = { | ||
children: ReactNode; | ||
}; | ||
|
||
export default function AppsListingLayout(props: { children: ReactNode }) { | ||
export default function AppsListingLayout({ | ||
children, | ||
}: AppsListingLayoutProps) { | ||
return ( | ||
<main> | ||
<h1 className={styles.title}>Apps</h1> | ||
{props.children} | ||
<SessionProvider>{children}</SessionProvider> | ||
</main> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,45 @@ | ||
"use client"; | ||
|
||
import { AppList } from "@/components/AppList"; | ||
import { SessionProvider, useSession } from "next-auth/react"; | ||
import { LoginButton } from "@/components/LoginButton"; | ||
import { useEffect, useState } from "react"; | ||
import { | ||
getAppsResponse, | ||
getCategoriesResponse, | ||
getDevicesResponse, | ||
} from "@/badgehub-api-client/generated/swagger/public/public"; | ||
import { getAppData } from "../actions"; | ||
|
||
export interface SearchParams { | ||
category: string; | ||
device: string; | ||
} | ||
|
||
export default async function Listing({ | ||
export default function Listing({ | ||
searchParams, | ||
}: { | ||
searchParams: Partial<SearchParams>; | ||
}) { | ||
let data; | ||
try { | ||
// TODO add caching | ||
data = await getAppData(searchParams); | ||
} catch (e) { | ||
if (!(e instanceof Error)) { | ||
return <p>Caught object that wasn&t an error.</p>; | ||
const { data: session } = useSession(); | ||
const [data, setData] = useState< | ||
[getAppsResponse, getCategoriesResponse, getDevicesResponse] | null | ||
>(null); | ||
|
||
useEffect(() => { | ||
async function getData() { | ||
const token = (session as any)?.accessToken; | ||
const data = await getAppData(searchParams, token); | ||
setData(data); | ||
} | ||
return ( | ||
<> | ||
<p>Error while rendering</p> | ||
<code> | ||
<pre>{JSON.stringify(e.message)}</pre> | ||
</code> | ||
</> | ||
); | ||
} | ||
|
||
getData(); | ||
}, [searchParams, session]); | ||
|
||
return ( | ||
<> | ||
<LoginButton /> | ||
<AppList data={data} /> | ||
{data ? <AppList data={data} /> : <p>Loading new data...</p>} | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* Generated by orval v7.1.1 🍺 | ||
* Do not edit manually. | ||
* badgehub-api | ||
* Node project for the BadgeHub API | ||
* OpenAPI spec version: 3 | ||
*/ | ||
|
||
export interface App { | ||
category_slug: string; | ||
name: string; | ||
slug: string; | ||
user_name: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* Generated by orval v7.1.1 🍺 | ||
* Do not edit manually. | ||
* badgehub-api | ||
* Node project for the BadgeHub API | ||
* OpenAPI spec version: 3 | ||
*/ | ||
|
||
export interface AppDetails { | ||
category_slug: string; | ||
description: string; | ||
devices: string[]; | ||
name: string; | ||
slug: string; | ||
user_name: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** | ||
* Generated by orval v7.1.1 🍺 | ||
* Do not edit manually. | ||
* badgehub-api | ||
* Node project for the BadgeHub API | ||
* OpenAPI spec version: 3 | ||
*/ | ||
|
||
export interface Device { | ||
name: string; | ||
slug: string; | ||
} |
11 changes: 11 additions & 0 deletions
11
src/badgehub-api-client/generated/models/getAppDetails404.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* Generated by orval v7.1.1 🍺 | ||
* Do not edit manually. | ||
* badgehub-api | ||
* Node project for the BadgeHub API | ||
* OpenAPI spec version: 3 | ||
*/ | ||
|
||
export type GetAppDetails404 = { | ||
reason: string; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters