feat(auth): Add authorize page
This commit is contained in:
@@ -5,23 +5,40 @@ import { cookies } from "next/headers";
|
||||
|
||||
import { AuthorizeContainer } from "@/components/core/authorize";
|
||||
|
||||
export default async function AuthorizePage({ searchParams }: { searchParams: Promise<{ [key: string]: string | string[] | undefined }> }) {
|
||||
export interface AuthorizeParams {
|
||||
client_id?: string,
|
||||
response_type?: string,
|
||||
redirect_uri?: string,
|
||||
scope?: string,
|
||||
state?: string,
|
||||
}
|
||||
|
||||
export default async function AuthorizePage({ searchParams }: { searchParams: Promise<AuthorizeParams> }) {
|
||||
const params = await searchParams;
|
||||
|
||||
const cookieStore = await cookies();
|
||||
const token = cookieStore.get("token");
|
||||
if (!token) {
|
||||
redirect("/");
|
||||
}
|
||||
|
||||
|
||||
const queryString = new URLSearchParams(
|
||||
Object.entries(params).filter(([, v]) => v !== undefined) as [string, string][]
|
||||
).toString();
|
||||
|
||||
const client_id = params.client_id as string;
|
||||
const redirect_uri = params.redirect_uri as string;
|
||||
const response_type = params.response_type as string || "code";
|
||||
const scope = params.scope as string || "profile email";
|
||||
if (!token) {
|
||||
redirect(`/?returnTo=/authorize?${queryString}`);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex justify-center items-center h-screen">
|
||||
<AuthorizeContainer applicationName="SecNex" applicationUrl="https://secnex.io" client_id={client_id} redirect_uri={redirect_uri} response_type={response_type} scope={scope} />
|
||||
<AuthorizeContainer
|
||||
applicationName="SecNex"
|
||||
applicationUrl="https://secnex.io"
|
||||
client_id={params.client_id || ""}
|
||||
redirect_uri={params.redirect_uri || ""}
|
||||
response_type={params.response_type || "code"}
|
||||
scope={params.scope || "profile email"}
|
||||
returnTo={`/authorize?${queryString}`}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user