Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

auth-nextjs: rename to gel #1153

Open
wants to merge 1 commit into
base: gel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions packages/auth-nextjs/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "@edgedb/auth-nextjs",
"description": "Helper library to integrate the EdgeDB Auth extension with Next.js",
"name": "@gel/auth-nextjs",
"description": "Helper library to integrate the Gel Auth extension with Next.js",
"version": "0.3.2",
"author": "EdgeDB <info@edgedb.com>",
"author": "Gel <info@gel.com>",
"repository": {
"type": "git",
"url": "https://github.com/edgedb/edgedb-js.git",
"url": "https://github.com/gel/gel-js.git",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will may need an update

"directory": "packages/auth-nextjs"
},
"license": "Apache-2.0",
Expand All @@ -28,18 +28,18 @@
"@repo/tsconfig": "*",
"@types/node": "^20.12.13",
"@types/react": "npm:types-react@rc",
"edgedb": "*",
"gel": "*",
"next": "15.0.3",
"react": "19.0.0-rc-b01722d5-20241114",
"typescript": "^5.5.2"
},
"peerDependencies": {
"edgedb": "^1.3.6",
"gel": "^1.3.6",
"next": ">=13.5.6 <16.0.0",
"react": "^18.2.0 || ^19.0"
},
"dependencies": {
"@edgedb/auth-core": "0.2.1"
"@gel/auth-core": "0.2.1"
},
"overrides": {
"@types/react": "npm:types-react@rc"
Expand Down
23 changes: 12 additions & 11 deletions packages/auth-nextjs/readme.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
# @edgedb/auth-nextjs: Helper library to integrate the EdgeDB Auth extension with Next.js
# @gel/auth-nextjs: Helper library to integrate the Gel Auth extension with Next.js

> Warning: This library is still in an alpha state, and so, bugs are likely and the api's should be considered unstable and may change in future releases.

### Setup

**Prerequisites**:

- Node v18+
- **Note**: Due to using the `crypto` global, you will need to start Node with `--experimental-global-webcrypto`. You can add this option to your `NODE_OPTIONS` environment variable, like `NODE_OPTIONS='--experimental-global-webcrypto'` in the appropriate `.env` file.
- Before adding EdgeDB auth to your Next.js app, you will first need to enable the `auth` extension in your EdgeDB schema, and have configured the extension with some providers. Refer to the auth extension docs for details on how to do this.
- Before adding Gel auth to your Next.js app, you will first need to enable the `auth` extension in your Gel schema, and have configured the extension with some providers. Refer to the auth extension docs for details on how to do this.

1. Initialize the auth helper by passing an EdgeDB `Client` object to `createAuth()`, along with some configuration options. This will return a `NextAppAuth` object which you can use across your app. Similarly to the `Client` it's recommended to export this auth object from some root configuration file in your app.
1. Initialize the auth helper by passing an Gel `Client` object to `createAuth()`, along with some configuration options. This will return a `NextAppAuth` object which you can use across your app. Similarly to the `Client` it's recommended to export this auth object from some root configuration file in your app.

```ts
// edgedb.ts
// gel.ts

import { createClient } from "edgedb";
import createAuth from "@edgedb/auth-nextjs/app";
import { createClient } from "gel";
import createAuth from "@gel/auth-nextjs/app";

export const client = createClient();

Expand All @@ -28,8 +29,8 @@

- `baseUrl: string`, _required_, The url of your application; needed for various auth flows (eg. OAuth) to redirect back to.
- `authRoutesPath?: string`, The path to the auth route handlers, defaults to `'auth'`, see below for more details.
- `authCookieName?: string`, The name of the cookie where the auth token will be stored, defaults to `'edgedb-session'`.
- `pkceVerifierCookieName?: string`: The name of the cookie where the verifier for the PKCE flow will be stored, defaults to `'edgedb-pkce-verifier'`
- `authCookieName?: string`, The name of the cookie where the auth token will be stored, defaults to `'gel-session'`.
- `pkceVerifierCookieName?: string`: The name of the cookie where the verifier for the PKCE flow will be stored, defaults to `'gel-pkce-verifier'`
- `passwordResetPath?: string`: The path relative to the `baseUrl` of the the password reset page; needed if you want to enable password reset emails in your app.
- `magicLinkFailurePath?: string`: The path relative to the `baseUrl` of the page we should redirect users to if there is an error when trying to sign in with a magic link. The page will get an `error` search parameter attached with an error message. This property is required if you use the Magic Link authentication feature.

Expand All @@ -39,7 +40,7 @@
// app/auth/[...auth]/route.ts

import { redirect } from "next/navigation";
import { auth } from "@/edgedb";
import { auth } from "@/gel";

const { GET, POST } = auth.createAuthRouteHandlers({
onOAuthCallback({ error, tokenData, isSignUp }) {
Expand Down Expand Up @@ -68,7 +69,7 @@

By default the handlers expect to exist under the `/auth` path in your app, however if you want to place them elsewhere, you will also need to configure the `authRoutesPath` option of `createAuth` to match.

3. Now we just need to setup the UI to allow your users to sign in/up, etc. The easiest way to get started is to use the EdgeDB Auth's builtin UI. Or alternatively you can implement your own custom UI.
3. Now we just need to setup the UI to allow your users to sign in/up, etc. The easiest way to get started is to use the Gel Auth's builtin UI. Or alternatively you can implement your own custom UI.

**Builtin UI**

Expand Down Expand Up @@ -97,7 +98,7 @@
Now you have auth all configured and user's can signin/signup/etc. you can use the `auth.getSession()` method in your app pages to retrieve an `AuthSession` object. This session object allows you to check if the user is currently logged in with the `isSignedIn` method, and also provides a `Client` object automatically configured with the `ext::auth::client_token` global, so you can run queries using the `ext::auth::ClientTokenIdentity` of the currently signed in user.

```ts
import { auth } from "@/edgedb";
import { auth } from "@/gel";

export default async function Home() {
const session = await auth.getSession();
Expand Down
2 changes: 1 addition & 1 deletion packages/auth-nextjs/src/app/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
type NextAuthOptions,
} from "../shared.client";

export * from "@edgedb/auth-core/errors";
export * from "@gel/auth-core/errors";
export { type NextAuthOptions, type BuiltinProviderNames };

export default function createNextAppClientAuth(options: NextAuthOptions) {
Expand Down
6 changes: 3 additions & 3 deletions packages/auth-nextjs/src/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import {
ConfigurationError,
PKCEError,
InvalidDataError,
} from "@edgedb/auth-core";
import type { Client } from "edgedb";
} from "@gel/auth-core";
import type { Client } from "gel";
import { cookies } from "next/headers";
import { cache } from "react";

Expand All @@ -17,7 +17,7 @@ import {
_extractParams,
} from "../shared";

export * from "@edgedb/auth-core/errors";
export * from "@gel/auth-core/errors";
export {
NextAuthSession,
type NextAuthOptions,
Expand Down
4 changes: 2 additions & 2 deletions packages/auth-nextjs/src/pages/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import {
NextAuthHelpers,
type NextAuthOptions,
} from "../shared.client";
import { errorMapping } from "@edgedb/auth-core/utils";
import { errorMapping } from "@gel/auth-core/utils";

export * from "@edgedb/auth-core/errors";
export * from "@gel/auth-core/errors";
export { type NextAuthOptions, type BuiltinProviderNames };

export default function createNextPagesClientAuth(options: NextAuthOptions) {
Expand Down
6 changes: 3 additions & 3 deletions packages/auth-nextjs/src/pages/server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type Client } from "edgedb";
import { type TokenData } from "@edgedb/auth-core";
import { type Client } from "gel";
import { type TokenData } from "@gel/auth-core";
import {
type BuiltinProviderNames,
type CreateAuthRouteHandlers,
Expand All @@ -8,7 +8,7 @@ import {
NextAuthSession,
} from "../shared";

export * from "@edgedb/auth-core/errors";
export * from "@gel/auth-core/errors";
export {
NextAuthSession,
type NextAuthOptions,
Expand Down
10 changes: 5 additions & 5 deletions packages/auth-nextjs/src/shared.client.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {
type BuiltinOAuthProviderNames,
type emailPasswordProviderName,
} from "@edgedb/auth-core";
import { WebAuthnClient } from "@edgedb/auth-core/webauthn";
} from "@gel/auth-core";
import { WebAuthnClient } from "@gel/auth-core/webauthn";

export * as webauthn from "@edgedb/auth-core/webauthn";
export * as webauthn from "@gel/auth-core/webauthn";

export type BuiltinProviderNames =
| BuiltinOAuthProviderNames
Expand Down Expand Up @@ -33,9 +33,9 @@ export abstract class NextAuthHelpers {
this.options = {
baseUrl: options.baseUrl.replace(/\/$/, ""),
authRoutesPath: options.authRoutesPath?.replace(/^\/|\/$/g, "") ?? "auth",
authCookieName: options.authCookieName ?? "edgedb-session",
authCookieName: options.authCookieName ?? "gel-session",
pkceVerifierCookieName:
options.pkceVerifierCookieName ?? "edgedb-pkce-verifier",
options.pkceVerifierCookieName ?? "gel-pkce-verifier",
passwordResetPath: options.passwordResetPath,
magicLinkFailurePath: options.magicLinkFailurePath,
};
Expand Down
10 changes: 5 additions & 5 deletions packages/auth-nextjs/src/shared.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { type Client } from "edgedb";
import { type Client } from "gel";
import {
Auth,
type BuiltinOAuthProviderNames,
type TokenData,
ConfigurationError,
InvalidDataError,
PKCEError,
EdgeDBAuthError,
GelAuthError,
OAuthProviderFailureError,
type SignupResponse,
} from "@edgedb/auth-core";
} from "@gel/auth-core";

import {
type BuiltinProviderNames,
Expand Down Expand Up @@ -527,7 +527,7 @@ export abstract class NextAuth extends NextAuthHelpers {
const desc = req.nextUrl.searchParams.get("error_description");
return onBuiltinUICallback(
{
error: new EdgeDBAuthError(error + (desc ? `: ${desc}` : "")),
error: new GelAuthError(error + (desc ? `: ${desc}` : "")),
},
req,
);
Expand Down Expand Up @@ -1034,7 +1034,7 @@ function _wrapResponse(res: Promise<Response> | undefined, isAction: boolean) {
function _wrapError(err: Error) {
return {
_error: {
type: err instanceof EdgeDBAuthError ? err.type : null,
type: err instanceof GelAuthError ? err.type : null,
message: err instanceof Error ? err.message : String(err),
},
};
Expand Down
Loading