Skip to content

Commit

Permalink
fix: ci/cd
Browse files Browse the repository at this point in the history
  • Loading branch information
amjed-ali-k committed Oct 14, 2023
1 parent 85c041f commit e209d0d
Show file tree
Hide file tree
Showing 14 changed files with 53 additions and 28 deletions.
6 changes: 5 additions & 1 deletion next.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
/** @type {import('next').NextConfig} */
const nextConfig = {};
const nextConfig = {
experimental: {
serverActions: true,
},
};

module.exports = nextConfig;
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/app/api/secure/batches/all/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { getUserId } from "@/components/auth/server";

export async function GET(request: NextRequest) {
const userId = await getUserId(request);
if (!userId)
return NextResponse.json({ message: "Unauthenticated" }, { status: 401 });

const results = await prisma.batch.findMany({
where: {
Expand Down
3 changes: 3 additions & 0 deletions src/app/api/secure/batches/new/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ const schema = z.object({

export async function GET(request: NextRequest) {
const userId = await getUserId(request);
if (!userId)
return NextResponse.json({ message: "Unauthenticated" }, { status: 401 });

const body = schema.safeParse(await request.json());
if (!body.success) {
const { errors } = body.error;
Expand Down
2 changes: 2 additions & 0 deletions src/app/api/secure/branches/all/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { getUserId } from "@/components/auth/server";

export async function GET(request: NextRequest) {
const userId = await getUserId(request);
if (!userId)
return NextResponse.json({ message: "Unauthenticated" }, { status: 401 });

const results = await prisma.branch.findMany({
select: {
Expand Down
5 changes: 5 additions & 0 deletions src/app/api/secure/profile/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ export async function PUT(request: NextRequest) {
{ status: 400 }
);
}

const userId = await getUserId(request);
if (!userId)
return NextResponse.json({ message: "Unauthenticated" }, { status: 401 });

const res = await prisma.user.upsert({
where: {
Expand Down Expand Up @@ -58,6 +61,8 @@ export async function PUT(request: NextRequest) {

export async function GET(request: NextRequest) {
const userId = await getUserId(request);
if (!userId)
return NextResponse.json({ message: "Unauthenticated" }, { status: 401 });

const res = await prisma.user.findUnique({
where: {
Expand Down
2 changes: 2 additions & 0 deletions src/app/api/secure/sbte-result/history/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { getUserId } from "@/components/auth/server";

export async function GET(request: NextRequest) {
const userId = await getUserId(request);
if (!userId)
return NextResponse.json({ message: "Unauthenticated" }, { status: 401 });

const results = await prisma.examResultFormatHistory.findMany({
where: {
Expand Down
2 changes: 2 additions & 0 deletions src/app/api/secure/sbte-result/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ export async function POST(request: NextRequest) {
);
}
const userId = await getUserId(request);
if (!userId)
return NextResponse.json({ message: "Unauthenticated" }, { status: 401 });

const myProfile = await prisma.user.findUnique({
where: {
Expand Down
2 changes: 2 additions & 0 deletions src/app/api/secure/sbte-result/single/[resultId]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export async function GET(
{ params }: { params: { resultId: string } }
) {
const userId = await getUserId(request);
if (!userId)
return NextResponse.json({ message: "Unauthenticated" }, { status: 401 });

const results = await prisma.examResultFormatHistory.findUnique({
where: {
Expand Down
3 changes: 3 additions & 0 deletions src/app/auth/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import SBTEToolsLogo from "@/components/Logo";
import HankoAuth from "@/components/auth/HankoAuth";

// CI fails without this
export const dynamic = "force-dynamic";

export default function LoginPage() {
return (
<>
Expand Down
1 change: 1 addition & 0 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const inter = Inter({ subsets: ["latin"] });

export const metadata: Metadata = {
title: "Poly Tools",
metadataBase: new URL("https://poly-tools.vercel.app"),
keywords: [
"SBTE",
"SBTE Tools",
Expand Down
4 changes: 1 addition & 3 deletions src/components/auth/HankoAuth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
import { useEffect, useCallback, useState } from "react";
import { useRouter } from "next/navigation";
import { register } from "@teamhanko/hanko-elements";

import { Hanko } from "@teamhanko/hanko-frontend-sdk";
import type { Hanko } from "@teamhanko/hanko-frontend-sdk";

const hankoApi = process.env.NEXT_PUBLIC_HANKO_API_URL!;

export default function HankoAuth({ className }: { className?: string }) {
console.log("API URL", hankoApi);
const router = useRouter();

const [hanko, setHanko] = useState<Hanko>();
Expand Down
29 changes: 15 additions & 14 deletions src/components/auth/server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import axios from "axios";
"use server";
import { hankoApiUrl } from "./vars";
import { createRemoteJWKSet, jwtVerify } from "jose";
import { NextRequest } from "next/server";
Expand All @@ -14,17 +14,18 @@ export const fetchUserId = async (hanko: string) => {
};

export const getUserId = async (req: NextRequest) => {
// const userId = req.headers.get("x-user-id");
const hanko = req.cookies.get("hanko")?.value;
if (!hanko) {
throw new Error("No Hanko cookie found");
}
const userId = await fetchUserId(hanko);
// validate userId is uuid using zod
const schema = z.string().uuid();
const validatedUserId = schema.safeParse(userId);
if (!validatedUserId.success) {
throw new Error("Invalid user id");
}
return validatedUserId.data;
const userId = req.headers.get("x-user-id");
return userId;
// const hanko = req.cookies.get("hanko")?.value ?? "";
// if (!hanko) {
// throw new Error("No Hanko cookie found");
// }
// const userId = await fetchUserId(hanko);
// // validate userId is uuid using zod
// const schema = z.string().uuid();
// const validatedUserId = schema.safeParse(userId);
// if (!validatedUserId.success) {
// throw new Error("Invalid user id");
// }
// return validatedUserId.data;
};
2 changes: 1 addition & 1 deletion src/components/home/SignInButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function SignInButton() {
>
<Link href="/auth">
<span className="inline-flex h-full w-fit items-center gap-1 rounded-sm px-4 py-2 transition-all duration-300 dark:bg-neutral-900 dark:text-white group-hover:dark:bg-black">
{loading || status === "loading" ? (
{loading ? (
<Loader2 className="h-5 w-5 animate-spin" />
) : (
<LogIn className="mr-1 h-4 w-4 stroke-[3]" />
Expand Down

0 comments on commit e209d0d

Please sign in to comment.