feat: ci/cd
This commit is contained in:
@@ -27,7 +27,7 @@ export async function clearTokens() {
|
||||
store.delete("refresh_token");
|
||||
}
|
||||
|
||||
async function tryRefresh(): Promise<boolean> {
|
||||
export async function tryRefresh(): Promise<boolean> {
|
||||
if (refreshPromise) return refreshPromise;
|
||||
|
||||
refreshPromise = (async () => {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
import { Consent } from "@/types"
|
||||
import { cookies } from "next/headers"
|
||||
import { clearTokens, tryRefresh } from "./auth"
|
||||
|
||||
export async function getConsents() {
|
||||
const store = await cookies()
|
||||
@@ -15,15 +16,24 @@ export async function getConsents() {
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
if (response.status === 401) {
|
||||
const refreshed = await tryRefresh();
|
||||
if (!refreshed) {
|
||||
await clearTokens();
|
||||
return null;
|
||||
}
|
||||
return getConsents();
|
||||
}
|
||||
|
||||
if (!response.ok) return []
|
||||
|
||||
var consents = await response.json() as Consent[];
|
||||
consents.forEach((consent: Consent) => {
|
||||
if (consent.client_id == process.env.CLIENT_ID) {
|
||||
consent.isRevokable == false
|
||||
consent.isRevokable = false
|
||||
} else {
|
||||
consent.isRevokable == true
|
||||
consent.isRevokable = true
|
||||
}
|
||||
});
|
||||
|
||||
@@ -35,7 +45,7 @@ export async function revokeConsent(clientId: string) {
|
||||
const accessToken = store.get("access_token")?.value
|
||||
|
||||
const response = await fetch(
|
||||
`${process.env.KOTOSOFT_ID_API_URL}/api/v1/me/applications/${clientId}`,
|
||||
`${process.env.KOTOSOFT_ID_API_URL}/api/v1/me/consents/${clientId}`,
|
||||
{
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
|
||||
@@ -13,7 +13,7 @@ import Applications from "./items/applications";
|
||||
|
||||
interface Props {
|
||||
userData: User | null;
|
||||
consentsData: Consent[] | [];
|
||||
consentsData: Consent[] | null;
|
||||
}
|
||||
|
||||
export default function MeClient({ userData, consentsData }: Props) {
|
||||
|
||||
@@ -9,7 +9,7 @@ import { enUS } from "date-fns/locale";
|
||||
import { format } from "date-fns";
|
||||
|
||||
interface Props {
|
||||
consents: Consent[] | [];
|
||||
consents: Consent[] | null;
|
||||
setConsents: (consents: Consent[]) => void;
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ export default function Applications({ consents, setConsents }: Props) {
|
||||
<h1 className="text-xl">{t("title")}</h1>
|
||||
|
||||
<div className="space-y-4">
|
||||
{consents.map((consent) => (
|
||||
{consents?.map((consent) => (
|
||||
<Item key={consent.client_id}>
|
||||
<ItemContent>
|
||||
<ItemTitle>{consent.client_name}</ItemTitle>
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import { getSession } from "@/actions/oauth";
|
||||
import { isRedirectError } from "next/dist/client/components/redirect-error";
|
||||
import { cookies } from "next/headers";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export default async function OAuthPage({
|
||||
searchParams,
|
||||
}: {
|
||||
@@ -14,10 +17,28 @@ export default async function OAuthPage({
|
||||
const data = await getSession(session);
|
||||
if (!data) redirect("/oauth/error");
|
||||
|
||||
const isAuthenticated =
|
||||
data.user_id && data.user_id !== "00000000-0000-0000-0000-000000000000";
|
||||
const store = await cookies();
|
||||
const accessToken = store.get("access_token")?.value;
|
||||
|
||||
redirect(isAuthenticated ? `/consent?session=${session}` : `/login?session=${session}`);
|
||||
if (accessToken) {
|
||||
const res = await fetch(`${process.env.KOTOSOFT_ID_API_URL}/oauth/session/attach`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${accessToken}`
|
||||
},
|
||||
body: JSON.stringify({ session }),
|
||||
cache: "no-store",
|
||||
});
|
||||
|
||||
if (res.ok) {
|
||||
const body = await res.json();
|
||||
if (body.redirect_url) redirect(body.redirect_url);
|
||||
redirect(`/consent?session=${session}`);
|
||||
}
|
||||
}
|
||||
|
||||
redirect(`/login?session=${session}`);
|
||||
} catch (error) {
|
||||
if (isRedirectError(error)) throw error;
|
||||
console.error("OAuth page error:", error);
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
FROM node:20 AS builder
|
||||
WORKDIR /app
|
||||
COPY package.json package-lock.json* ./
|
||||
RUN npm install --include=dev
|
||||
COPY . .
|
||||
RUN npm run build
|
||||
|
||||
FROM node:20 AS production
|
||||
WORKDIR /app
|
||||
COPY package.json package-lock.json* ./
|
||||
COPY --from=builder /app/node_modules ./node_modules
|
||||
COPY --from=builder /app/.next ./.next
|
||||
COPY --from=builder /app/public ./public
|
||||
COPY --from=builder /app/messages ./messages
|
||||
RUN npm prune --omit=dev
|
||||
EXPOSE 80
|
||||
CMD ["npm", "start", "--", "-p", "80", "-H", "0.0.0.0"]
|
||||
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
||||
CMD wget -q --spider http://localhost:80/ || exit 1
|
||||
@@ -1,10 +1,7 @@
|
||||
import type { NextConfig } from "next";
|
||||
import createNextIntlPlugin from "next-intl/plugin";
|
||||
|
||||
const nextConfig: NextConfig = {
|
||||
/* config options here */
|
||||
};
|
||||
|
||||
const nextConfig: NextConfig = {};
|
||||
|
||||
const withNextIntl = createNextIntlPlugin();
|
||||
export default withNextIntl(nextConfig);
|
||||
|
||||
Reference in New Issue
Block a user