Git Product home page Git Product logo

net3-starter's Introduction

NET3 = Next.js + EdgeDB + T3 (Tailwind, TypeScript, tRPC)

This is Next.js + EdgeDB starter project bootstraped on the T3 Stack

Note

Project uses unstable apis such as the EdgeDB auth extension

Installation Steps

TBD

EdgeDB

1. Install

2. Instatiate & Migrate

3. Configure the Auth extension

Set the allowed redirect url via the REPL (run edgedb):

configure current database set ext::auth::AuthConfig::allowed_redirect_urls := {"http://localhost:3000/"}

Docs

i18n

  • ✅ Works for client & server components and server actions.
  • ✅ Support for active pathname checks via useLngPathname().
  • ✅ Extraction of translation keys via i18next-parser.
  • ✅ Integrated with zod both for key translation & extraction including custom translation keys.

Configuration

  1. Add your language code into options array.
  2. Import your zod translations and add into resources map
  3. Run npm run i18n which will create empty folders & json maps for your locales from added in step 1.
  4. Fill the translations & commit changes.
  5. 🎉 Your app is translated!

Server Components

/**
 * Use the custom RSC Params type which gives you the global `[lng]` param.
 */
import { Params } from "@/types";
/**
 * Import the SSR translations hook from a local `i18n` folder.
 * NOTE: the SSR hook is awaited!
 */
import { useTranslation } from "@/i18n";

export default async function Page({ params: { lng } }: Params) {
  // Specify the feature name as your namespace.
  // Use the "global" namespace for reusable components like Button.
  const { t } = await useTranslation("feature", lng);

  return <h1>{t("title")}</h1>;
}

You can also use this 'hook' in the server actions. See the auth actions as an example.

Client Components

In client components, we use the hook useTranslation() from a library.

import { useTranslation } from "react-i18next";

export function CreateUserForm() {
  const { t } = useTranslation("onboarding");
}

On the client side, the import of translation files is handled in the RootLayout by the <Language /> component.

Client Navigation Components

Since the [lng] param is present in every pathname, we extend the usePathame() from Next.js, with a functionality to strip the prefix away, so you can check for active path easily:

"use client";
/**
 * Import useLngPathname instead of the usePathname
 */
import { useLngPathname } from "@/i18n";
/**
 * Get the type for prop which will be passed from the server component params.
 */
import { type LanguageParam } from "@/i18n";

export function Navbar({ lng }: LanguageParam) {
  // pathname no longer contains the lng prefix!
  const pathname = useLngPathname(lng);
  const { t } = useTranslation("global");

  // we can check if the path is active without worrying about the language:
  return (
    <nav>
      <NavbarLink href="/dashboard" active={pathname.startsWith("/dashboard")}>
        {t("dashboard")}
      </NavbarLink>
    </nav>
  );
}

See full code of the <Navbar />.

Custom Zod Errors

When you use .refine() API of zod, the custom error must be defined in params as follows:

/**
 * The local "t" function is necessary for the i18next-parser to extract the translation key properly.
 */
import { t } from "@/i18n";

const customError = z.string().refine((val) => val, {
  // The "zodError" namespace here is mandatory & typechecked
  // The actual key, will be passed down to the zod-i18n-map which will do the translation.
  params: { i18n: t("zodError:passwordsMustMatch") },
});

See the translation of the passwordsMustMatch refinement .

FAQ

How does the query client connect to the EdgeDB?

In development, the library automatically detects the linked edgedb project. In production EDGEDB_DSN env variable is recommended.

How does Next.js communicate with the EdgeDB Auth extension?

Using the @edgedb/auth-nextjs

How do I deploy this?

TBD

Database Connection refused (often on Windows 11)

  1. Configure EdgeDB. See Source.
edgedb configure set listen_addresses 127.0.0.1 ::1
  1. or Update operating system routing

  2. or configure the app (not recommended)

// env.mjs or elsewhere where it suits you
import dns from "node:dns";
dns.setDefaultResultOrder("ipv4first");

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.