Skip to content

Commit

Permalink
Merge branch 'fix/bugs' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
rharkor committed Jul 30, 2024
2 parents 424028c + 0cb805b commit 9f3457a
Show file tree
Hide file tree
Showing 16 changed files with 166 additions and 110 deletions.
4 changes: 2 additions & 2 deletions apps/app/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ COPY turbo.json ./
COPY apps/app/package.json ./apps/app/package.json
COPY apps/app/prisma/schema.prisma apps/app/prisma/schema.prisma
COPY packages/lib/package.json ./packages/lib/package.json
COPY packages/emails/package.json ./packages/emails/package.json
COPY packages/transactional/package.json ./packages/transactional/package.json

RUN npm ci --omit=dev

Expand All @@ -41,7 +41,7 @@ COPY --from=deps /usr/src/app .
COPY apps/app ./apps/app
COPY packages/configs ./packages/configs
COPY packages/lib ./packages/lib
COPY packages/emails ./packages/emails
COPY packages/transactional ./packages/transactional


RUN turbo run build --filter=@next-boilerplate/app
Expand Down
73 changes: 73 additions & 0 deletions apps/app/debug/api-routes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import SuperJSON from "superjson"

import { AppRouter } from "@/api/_app"
import { env } from "@/lib/env"
import { getBaseUrl } from "@/lib/trpc/utils"
import { logger } from "@next-boilerplate/lib"
import { createTRPCClient, httpBatchLink } from "@trpc/client"

// Insert your token here (for authenticated requests)
let token: string | undefined = undefined
const getAuthCookie = () => {
return token
}

const signIn = async () => {
const csrfResponse = await fetch(`${env.NEXT_PUBLIC_BASE_URL}/api/auth/csrf`)
// Get csrf token from cookies
const csrfSetCookies = (csrfResponse.headers.get("set-cookie") ?? "")
.replace(/Path=\/; HttpOnly; SameSite=Lax,?\s?/g, "")
.replace(/;\s?$/g, "")
// Extract authjs.csrf-token=
const csrfToken = csrfSetCookies.split("authjs.csrf-token=")[1].split(";")[0]

const formData = new URLSearchParams()
if (!env.NEXT_PUBLIC_DEMO_EMAIL || !env.NEXT_PUBLIC_DEMO_PASSWORD) {
logger.error("Please provide a demo email and password in your .env file")
return
}
formData.append("email", env.NEXT_PUBLIC_DEMO_EMAIL)
formData.append("password", env.NEXT_PUBLIC_DEMO_PASSWORD)
const credentialsResponse = await fetch(`${env.NEXT_PUBLIC_BASE_URL}/api/auth/callback/credentials?`, {
headers: {
cookie: csrfSetCookies,
"Content-Type": "application/x-www-form-urlencoded",
},
body: `redirect=false&callbackUrl=%2Fexamples%2Fprofile&otp=undefined&csrfToken=${
csrfToken.split("%")[0]
}&${formData.toString()}`,
method: "POST",
redirect: "manual",
})
// Get auth token from cookies
const authSetCookies = credentialsResponse.headers.get("set-cookie") ?? ""
// Extract the token authjs.session-token=
const authCookie = authSetCookies.split("authjs.session-token=")[1].split(";")[0]
// Save the token
logger.success("Signed in")
token = authCookie
}

const client = createTRPCClient<AppRouter>({
links: [
httpBatchLink({
url: `${getBaseUrl()}/api/trpc`,
transformer: SuperJSON,
async headers() {
const token = getAuthCookie()
return {
cookie: token ? `authjs.session-token=${token}` : "",
}
},
}),
],
})

const main = async () => {
await signIn()

const me = await client.me.getAccount.query()
logger.info(me)
}

main()
1 change: 0 additions & 1 deletion apps/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@
"@types/react": "^18.2.19",
"babel-plugin-styled-components": "^2.1.4",
"fetch-mock": "^10.0.0",
"git-conventional-commits": "^2.6.5",
"isomorphic-fetch": "^3.0.0",
"jest": "^29.6.2",
"jest-environment-jsdom": "^29.7.0",
Expand Down
2 changes: 1 addition & 1 deletion apps/app/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ReactNode } from "react"
import { Metadata } from "next"

export const metadata: Metadata = {
title: "Home",
title: "Next.js boilerplate",
description: "Welcome to Next.js boilerplate",
}

Expand Down
20 changes: 14 additions & 6 deletions apps/app/src/app/not-found.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from "react"
import { Metadata } from "next"
import { cookies } from "next/headers"

import { ThemeProvider } from "@/components/theme/theme-provider"
import { fontSans } from "@/lib/fonts"
import { i18n, Locale } from "@/lib/i18n-config"
import { getDictionary } from "@/lib/langs"
Expand All @@ -10,6 +12,10 @@ import { Link } from "@nextui-org/link"

import UIProvider from "./[lang]/ui-provider"

export const metadata: Metadata = {
title: "Not found",
}

export default async function Page404MatchAll() {
const cookiesStore = cookies()
const savedLocale = cookiesStore.get("saved-locale")
Expand All @@ -24,12 +30,14 @@ export default async function Page404MatchAll() {
className={cn("h-dvh min-h-dvh bg-background font-sans antialiased", fontSans.variable, fontSans.className)}
>
<UIProvider>
<main className="container m-auto flex min-h-screen flex-1 flex-col items-center justify-center gap-3">
<h1 className="text-4xl font-bold">{dictionary.notFound}</h1>
<Button as={Link} href="/" color="primary" variant="flat">
{dictionary.goHome}
</Button>
</main>
<ThemeProvider attribute="class" defaultTheme="system" enableSystem>
<main className="container m-auto flex min-h-screen flex-1 flex-col items-center justify-center gap-3">
<h1 className="text-4xl font-bold">{dictionary.notFound}</h1>
<Button as={Link} href="/" color="primary" variant="flat">
{dictionary.goHome}
</Button>
</main>
</ThemeProvider>
</UIProvider>
</body>
</html>
Expand Down
6 changes: 0 additions & 6 deletions apps/landing/src/app/[lang]/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from "react"
import { Metadata } from "next"
import { redirect } from "next/navigation"

import { fontSans } from "@/lib/fonts"
Expand All @@ -8,11 +7,6 @@ import { cn } from "@/lib/utils"

import "../globals.css"

export const metadata: Metadata = {
title: "Next.js Landing Page",
description: "Welcome to Next.js landing page",
}

export async function generateStaticParams() {
return i18n.locales.map((locale) => ({ lang: locale }))
}
Expand Down
11 changes: 11 additions & 0 deletions apps/landing/src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { ReactNode } from "react"
import { Metadata } from "next"

export const metadata: Metadata = {
title: "Next.js Landing Page",
description: "Welcome to Next.js boilerplate",
}

export default async function RootLayout({ children }: { children: ReactNode }) {
return children
}
5 changes: 5 additions & 0 deletions apps/landing/src/app/not-found.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from "react"
import { Metadata } from "next"
import { cookies } from "next/headers"

import { fontSans } from "@/lib/fonts"
Expand All @@ -8,6 +9,10 @@ import { cn } from "@/lib/utils"
import { Button } from "@nextui-org/button"
import { Link } from "@nextui-org/link"

export const metadata: Metadata = {
title: "Not found",
}

export default async function Page404MatchAll() {
const cookiesStore = cookies()
const savedLocale = cookiesStore.get("saved-locale")
Expand Down
2 changes: 1 addition & 1 deletion apps/landing/src/langs/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"link": "Aller sur l'application"
},
"goHome": "Retour à l'accueil",
"notFound": "Page non trouvée"
"notFound": "Page introuvable"
}
Loading

0 comments on commit 9f3457a

Please sign in to comment.