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-remix: rename edgedb to gel #1151

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-remix/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "@edgedb/auth-remix",
"description": "Helper library to integrate the EdgeDB Auth extension with Remix",
"name": "@gel/auth-remix",
"description": "Helper library to integrate the Gel Auth extension with Remix",
"version": "0.2.2",
"author": "EdgeDB <info@edgedb.com>",
"author": "Gel <info@gel.com>",
"type": "module",
"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.

may need an update

"directory": "packages/auth-remix"
},
"license": "Apache-2.0",
Expand All @@ -23,14 +23,14 @@
"devDependencies": {
"@repo/tsconfig": "*",
"@types/node": "^20.12.13",
"edgedb": "*",
"gel": "*",
"typescript": "^5.5.2"
},
"peerDependencies": {
"edgedb": "^1.3.6"
"gel": "^1.3.6"
},
"dependencies": {
"@edgedb/auth-core": "^0.2.1",
"@gel/auth-core": "^0.2.1",
"@remix-run/server-runtime": "^2.9.2",
"cookie": "^0.6.0"
},
Expand Down
23 changes: 12 additions & 11 deletions packages/auth-remix/readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# @edgedb/auth-remix
# @gel/auth-remix

This library provides a set of utilities to help you integrate authentication into your [Remix](https://remix.run/) application.
It supports authentication with various OAuth providers, as well as email/password authentication.
Expand All @@ -8,15 +8,16 @@ It supports authentication with various OAuth providers, as well as email/passwo
This package is published on npm and can be installed with your package manager of choice.

```bash
npm install @edgedb/auth-remix
npm install @gel/auth-remix
```

## 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 Remix app, you will first need to enable the `auth` extension in your EdgeDB schema, and have configured the extension with some providers (you can do this in CLI or EdgeDB UI). Refer to the auth extension docs for details on how to do this.
- Before adding Gel auth to your Remix app, you will first need to enable the `auth` extension in your Gel schema, and have configured the extension with some providers (you can do this in CLI or Gel UI). Refer to the auth extension docs for details on how to do this.

1. Initialize the client auth helper by passing configuration options to `createClientAuth()`. This will return a `RemixClientAuth` object which you can use in your components. You can skip this part if you find it unnecessary and provide all your data through the loader (the next step), but we suggest having the client auth too and use it directly in your components to get OAuth, BuiltinUI and signout URLs.

Expand All @@ -25,7 +26,7 @@ npm install @edgedb/auth-remix

import createClientAuth, {
type RemixAuthOptions,
} from "@edgedb/auth-remix/client";
} from "@gel/auth-remix/client";

export const options: RemixAuthOptions = {
baseUrl: "http://localhost:3000",
Expand All @@ -37,13 +38,13 @@ const auth = createClientAuth(options);
export default auth;
```

2. Initialize the server auth helper by passing an EdgeDB `Client` object to `createServerAuth()`, along with configuration options. This will return a `RemixServerAuth` object which you can use across your app on the server side.
2. Initialize the server auth helper by passing an Gel `Client` object to `createServerAuth()`, along with configuration options. This will return a `RemixServerAuth` object which you can use across your app on the server side.

```ts
// app/services/auth.server.ts

import createServerAuth from "@edgedb/auth-remix/server";
import { createClient } from "edgedb";
import createServerAuth from "@gel/auth-remix/server";
import { createClient } from "gel";
import { options } from "./auth";

export const client = createClient({
Expand All @@ -58,8 +59,8 @@ export default auth;

- `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'`
- `passwordResetUrl?: string`: The url of the the password reset page; needed if you want to enable password reset emails in your app.

3. Setup the auth route handlers, with `auth.createAuthRouteHandlers()`. Callback functions can be provided to handle various auth events, where you can define what to do in the case of successful signin's or errors. You only need to configure callback functions for the types of auth you wish to use in your app.
Expand Down Expand Up @@ -89,7 +90,7 @@ export default auth;

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

4. 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.
4. 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 All @@ -108,7 +109,7 @@ export default auth;
- `emailPasswordResetPassword`
- `signout`
- `isPasswordResetTokenValid(resetToken: string)`: Checks if a password reset token is still valid.
- `getOAuthUrl(providerName: string)`: This method takes the name of an OAuth provider (make sure you configure providers you need in the auth ext config first using CLI or EdgeDB UI) and returns a link that will initiate the OAuth sign in flow for that provider. You will also need to configure the `onOAuthCallback` auth route handler.
- `getOAuthUrl(providerName: string)`: This method takes the name of an OAuth provider (make sure you configure providers you need in the auth ext config first using CLI or Gel UI) and returns a link that will initiate the OAuth sign in flow for that provider. You will also need to configure the `onOAuthCallback` auth route handler.

## Usage

Expand Down
8 changes: 4 additions & 4 deletions packages/auth-remix/src/client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { BuiltinOAuthProviderNames } from "@edgedb/auth-core";
import { WebAuthnClient } from "@edgedb/auth-core/webauthn";
import type { BuiltinOAuthProviderNames } from "@gel/auth-core";
import { WebAuthnClient } from "@gel/auth-core/webauthn";

export interface RemixAuthOptions {
baseUrl: string;
Expand Down Expand Up @@ -27,8 +27,8 @@ export class RemixClientAuth {
/** @internal */
constructor(options: RemixAuthOptions) {
this.options = {
authCookieName: "edgedb-session",
pkceVerifierCookieName: "edgedb-pkce-verifier",
authCookieName: "gel-session",
pkceVerifierCookieName: "gel-pkce-verifier",
...options,
baseUrl: options.baseUrl.replace(/\/$/, ""),
authRoutesPath: options.authRoutesPath?.replace(/^\/|\/$/g, "") ?? "auth",
Expand Down
10 changes: 5 additions & 5 deletions packages/auth-remix/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { redirect, json, type TypedResponse } from "@remix-run/server-runtime";
import * as cookie from "cookie";
import type { Client } from "edgedb";
import type { Client } from "gel";
import {
Auth,
builtinOAuthProviderNames,
Expand All @@ -12,14 +12,14 @@ import {
PKCEError,
BackendError,
OAuthProviderFailureError,
EdgeDBAuthError,
GelAuthError,
MagicLinkFailureError,
type AuthenticationResponseJSON,
type RegistrationResponseJSON,
} from "@edgedb/auth-core";
} from "@gel/auth-core";
import { type RemixAuthOptions, RemixClientAuth } from "./client.js";

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

export type BuiltinProviderNames =
Expand Down Expand Up @@ -334,7 +334,7 @@ export class RemixServerAuth extends RemixClientAuth {
if (error) {
const desc = searchParams.get("error_description");
return cbCall(onBuiltinUICallback, {
error: new EdgeDBAuthError(error + (desc ? `: ${desc}` : "")),
error: new GelAuthError(error + (desc ? `: ${desc}` : "")),
});
}
const code = searchParams.get("code");
Expand Down
Loading