Skip to content

Commit

Permalink
Linting and formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamedBassem committed Feb 6, 2024
1 parent 2518a99 commit 4c901d0
Show file tree
Hide file tree
Showing 15 changed files with 134 additions and 128 deletions.
18 changes: 6 additions & 12 deletions web/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
{
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.json",
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 12,
"sourceType": "module"
},
"extends": [
"next/core-web-vitals",
"eslint:recommended",
"plugin:react/recommended",
"plugin:react-hooks/recommended",
"plugin:@next/next/recommended",
"next",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"prettier"
]
],
"ignorePatterns": ["postcss.config.js"],
"rules": {
"no-redeclare": "off",
"@next/next/no-html-link-for-pages": "off"
}
}
2 changes: 1 addition & 1 deletion web/app/api/auth/[...nextauth]/route.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { authHandler } from "@/lib/auth";

export { authHandler as GET, authHandler as POST }
export { authHandler as GET, authHandler as POST };
105 changes: 56 additions & 49 deletions web/app/api/v1/links/route.ts
Original file line number Diff line number Diff line change
@@ -1,60 +1,67 @@
import { authOptions } from "@/lib/auth";
import prisma from "@/lib/prisma";
import { ZNewBookmarkedLinkRequest, ZGetLinksResponse, ZBookmarkedLink } from "@/lib/types/api/links";
import {
ZNewBookmarkedLinkRequest,
ZGetLinksResponse,
ZBookmarkedLink,
} from "@/lib/types/api/links";
import { getServerSession } from "next-auth";
import { NextRequest, NextResponse } from "next/server";

export async function POST(request: NextRequest) {
// TODO: We probably should be using an API key here instead of the session;
const session = await getServerSession(authOptions);
if (!session) {
return new Response(null, { status: 401 });
}

const linkRequest = ZNewBookmarkedLinkRequest.safeParse(await request.json());

if (!linkRequest.success) {
return NextResponse.json({
error: linkRequest.error.toString(),
}, { status: 400 });
}

const link = await prisma.bookmarkedLink.create({
data: {
url: linkRequest.data.url,
userId: session.user.id,
}
});

let response: ZBookmarkedLink = { ...link };

return NextResponse.json(response, { status: 201 });
// TODO: We probably should be using an API key here instead of the session;
const session = await getServerSession(authOptions);
if (!session) {
return new Response(null, { status: 401 });
}

const linkRequest = ZNewBookmarkedLinkRequest.safeParse(await request.json());

if (!linkRequest.success) {
return NextResponse.json(
{
error: linkRequest.error.toString(),
},
{ status: 400 },
);
}

const link = await prisma.bookmarkedLink.create({
data: {
url: linkRequest.data.url,
userId: session.user.id,
},
});

let response: ZBookmarkedLink = { ...link };

return NextResponse.json(response, { status: 201 });
}

export async function GET() {
// TODO: We probably should be using an API key here instead of the session;
const session = await getServerSession(authOptions);
if (!session) {
return new Response(null, { status: 401 });
}
const links = await prisma.bookmarkedLink.findMany({
where: {
userId: session.user.id,
},
// TODO: We probably should be using an API key here instead of the session;
const session = await getServerSession(authOptions);
if (!session) {
return new Response(null, { status: 401 });
}
const links = await prisma.bookmarkedLink.findMany({
where: {
userId: session.user.id,
},
select: {
id: true,
url: true,
createdAt: true,
details: {
select: {
id: true,
url: true,
createdAt: true,
details: {
select: {
title: true,
description: true,
imageUrl: true,
}
},
}
});

let response: ZGetLinksResponse = { links };
return NextResponse.json(response);
title: true,
description: true,
imageUrl: true,
},
},
},
});

let response: ZGetLinksResponse = { links };
return NextResponse.json(response);
}
38 changes: 19 additions & 19 deletions web/app/globals.css
Original file line number Diff line number Diff line change
@@ -1,76 +1,76 @@
@tailwind base;
@tailwind components;
@tailwind utilities;

@layer base {
:root {
--background: 0 0% 100%;
--foreground: 222.2 84% 4.9%;

--card: 0 0% 100%;
--card-foreground: 222.2 84% 4.9%;

--popover: 0 0% 100%;
--popover-foreground: 222.2 84% 4.9%;

--primary: 222.2 47.4% 11.2%;
--primary-foreground: 210 40% 98%;

--secondary: 210 40% 96.1%;
--secondary-foreground: 222.2 47.4% 11.2%;

--muted: 210 40% 96.1%;
--muted-foreground: 215.4 16.3% 46.9%;

--accent: 210 40% 96.1%;
--accent-foreground: 222.2 47.4% 11.2%;

--destructive: 0 84.2% 60.2%;
--destructive-foreground: 210 40% 98%;

--border: 214.3 31.8% 91.4%;
--input: 214.3 31.8% 91.4%;
--ring: 222.2 84% 4.9%;

--radius: 0.5rem;
}

.dark {
--background: 222.2 84% 4.9%;
--foreground: 210 40% 98%;

--card: 222.2 84% 4.9%;
--card-foreground: 210 40% 98%;

--popover: 222.2 84% 4.9%;
--popover-foreground: 210 40% 98%;

--primary: 210 40% 98%;
--primary-foreground: 222.2 47.4% 11.2%;

--secondary: 217.2 32.6% 17.5%;
--secondary-foreground: 210 40% 98%;

--muted: 217.2 32.6% 17.5%;
--muted-foreground: 215 20.2% 65.1%;

--accent: 217.2 32.6% 17.5%;
--accent-foreground: 210 40% 98%;

--destructive: 0 62.8% 30.6%;
--destructive-foreground: 210 40% 98%;

--border: 217.2 32.6% 17.5%;
--input: 217.2 32.6% 17.5%;
--ring: 212.7 26.8% 83.9%;
}
}

@layer base {
* {
@apply border-border;
}
body {
@apply bg-background text-foreground;
}
}
}
1 change: 1 addition & 0 deletions web/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Metadata } from "next";
import { Inter } from "next/font/google";
import "./globals.css";
import React from "react";

const inter = Inter({ subsets: ["latin"] });

Expand Down
2 changes: 1 addition & 1 deletion web/components.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
"components": "@/components",
"utils": "@/lib/utils"
}
}
}
11 changes: 8 additions & 3 deletions web/components/auth/logout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@ import { signOut } from "next-auth/react";

export const LogoutButton = () => {
return (
<button className="btn btn-ghost normal-case" onClick={() => signOut({
callbackUrl: "/",
})}>
<button
className="btn btn-ghost normal-case"
onClick={() =>
signOut({
callbackUrl: "/",
})
}
>
Sign Out
</button>
);
Expand Down
10 changes: 5 additions & 5 deletions web/lib/auth.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import NextAuth, { NextAuthOptions } from "next-auth"
import { PrismaAdapter } from "@next-auth/prisma-adapter"
import NextAuth, { NextAuthOptions } from "next-auth";
import { PrismaAdapter } from "@next-auth/prisma-adapter";
import AuthentikProvider from "next-auth/providers/authentik";
import serverConfig from "@/lib/config";
import prisma from "@/lib/prisma";
Expand All @@ -15,11 +15,11 @@ export const authOptions: NextAuthOptions = {
adapter: PrismaAdapter(prisma),
providers: providers,
callbacks: {
session({ session, token, user }) {
session({ session, user }) {
session.user = { ...user };
return session;
}
}
},
},
};

export const authHandler = NextAuth(authOptions);
12 changes: 6 additions & 6 deletions web/lib/config.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
function buildAuthentikConfig() {
let {id, secret, issuer} = process.env;
let { id, secret, issuer } = process.env;
if (!id || !secret || !issuer) {
return undefined;
}

return {
clientId: id,
clientSecret: secret,
issuer: issuer,
};
clientId: id,
clientSecret: secret,
issuer: issuer,
};
}

const serverConfig = {
auth: {
authentik: buildAuthentikConfig(),
}
},
};

export default serverConfig;
2 changes: 1 addition & 1 deletion web/lib/prisma.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PrismaClient } from '@prisma/client'
import { PrismaClient } from "@prisma/client";

const prisma = new PrismaClient();

Expand Down
15 changes: 7 additions & 8 deletions web/lib/types/api/links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,19 @@ export const ZBookmarkedLink = z.object({
url: z.string().url(),
createdAt: z.coerce.date(),

details: z.object({
title: z.string(),
description: z.string(),
imageUrl: z.string().url(),
}).nullish(),

details: z
.object({
title: z.string(),
description: z.string(),
imageUrl: z.string().url(),
})
.nullish(),
});
export type ZBookmarkedLink = z.infer<typeof ZBookmarkedLink>;


// POST /v1/links
export const ZNewBookmarkedLinkRequest = ZBookmarkedLink.pick({ url: true });


// GET /v1/links
export const ZGetLinksResponse = z.object({
links: z.array(ZBookmarkedLink),
Expand Down
4 changes: 2 additions & 2 deletions web/lib/types/next-auth.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import NextAuth, { DefaultSession } from "next-auth"
import { DefaultSession } from "next-auth";

declare module "next-auth" {
/**
* Returned by `useSession`, `getSession` and received as a prop on the `SessionProvider` React Context
*/
interface Session {
export interface Session {
user: {
id: string;
} & DefaultSession["user"];
Expand Down
6 changes: 3 additions & 3 deletions web/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type ClassValue, clsx } from "clsx"
import { twMerge } from "tailwind-merge"
import { type ClassValue, clsx } from "clsx";
import { twMerge } from "tailwind-merge";

export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
return twMerge(clsx(inputs));
}
Loading

0 comments on commit 4c901d0

Please sign in to comment.