diff --git a/packages/auth-sveltekit/package.json b/packages/auth-sveltekit/package.json index 841ec79aa..9562867ed 100644 --- a/packages/auth-sveltekit/package.json +++ b/packages/auth-sveltekit/package.json @@ -1,12 +1,12 @@ { - "name": "@edgedb/auth-sveltekit", - "description": "Helper library to integrate the EdgeDB Auth extension with Sveltekit.", + "name": "@gel/auth-sveltekit", + "description": "Helper library to integrate the Gel Auth extension with Sveltekit.", "version": "0.2.3", - "author": "EdgeDB ", + "author": "Gel ", "type": "module", "repository": { "type": "git", - "url": "https://github.com/edgedb/edgedb-js.git", + "url": "https://github.com/gel/gel-js.git", "directory": "packages/auth-sveltekit" }, "license": "Apache-2.0", @@ -24,16 +24,16 @@ "@repo/tsconfig": "*", "@sveltejs/kit": "^2.5.10", "@types/node": "^20.12.13", - "edgedb": "*", + "gel": "*", "svelte": "^4.2.17", "typescript": "^5.5.2", "vite": "^5.2.12" }, "peerDependencies": { - "edgedb": "^1.3.6" + "gel": "^1.3.6" }, "dependencies": { - "@edgedb/auth-core": "^0.2.1" + "@gel/auth-core": "^0.2.1" }, "exports": { "./*": "./dist/*.js" diff --git a/packages/auth-sveltekit/readme.md b/packages/auth-sveltekit/readme.md index 4654b5f03..f70544dd6 100644 --- a/packages/auth-sveltekit/readme.md +++ b/packages/auth-sveltekit/readme.md @@ -1,4 +1,4 @@ -# @edgedb/auth-sveltekit +# @gel/auth-sveltekit This library provides a set of utilities to help you integrate authentication into your [SvelteKit](https://kit.svelte.dev/) application. It supports authentication with various OAuth providers, as well as email/password authentication. @@ -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-sveltekit +npm install @gel/auth-sveltekit ``` ## 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 SvelteKit 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 SvelteKit 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. ### Client auth helper @@ -25,9 +26,7 @@ Initialize the client auth helper by passing configuration options to `createCli ```ts // src/lib/auth.ts -import createClientAuth, { - type AuthOptions, -} from "@edgedb/auth-sveltekit/client"; +import createClientAuth, { type AuthOptions } from "@gel/auth-sveltekit/client"; export const options: AuthOptions = { baseUrl: "http://localhost:5173", @@ -43,18 +42,18 @@ The available auth config options are as follows: - `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.   -### EdgeDB client +### Gel client -Lets create an EdgeDB client that you will need for creating server auth client. +Lets create an Gel client that you will need for creating server auth client. ```ts // src/lib/server/auth.ts -import { createClient } from "edgedb"; +import { createClient } from "gel"; export const client = createClient({ //Note: when developing locally you will need to set tls security to insecure, because the dev server uses self-signed certificates which will cause api calls with the fetch api to fail. @@ -64,13 +63,11 @@ export const client = createClient({ ### Server auth client -Create the server auth client in a handle hook. Firstly call `serverAuth` passing to it EdgeDB client you created in the previous step, along with configuration options from step 1. This will give you back the `createServerRequestAuth` and `createAuthRouteHook`. You should call `createServerRequestAuth` inside a handle to attach the server client to `event.locals`. Calling `createAuthRouteHook` will give you back a hook so you should just invoke it inside `sequence` and pass your auth route handlers to it. +Create the server auth client in a handle hook. Firstly call `serverAuth` passing to it Gel client you created in the previous step, along with configuration options from step 1. This will give you back the `createServerRequestAuth` and `createAuthRouteHook`. You should call `createServerRequestAuth` inside a handle to attach the server client to `event.locals`. Calling `createAuthRouteHook` will give you back a hook so you should just invoke it inside `sequence` and pass your auth route handlers to it. You can now access the server auth in all actions and load functions through `event.locals`. ```ts -import serverAuth, { - type AuthRouteHandlers, -} from "@edgedb/auth-sveltekit/server"; +import serverAuth, { type AuthRouteHandlers } from "@gel/auth-sveltekit/server"; import { redirect, type Handle } from "@sveltejs/kit"; import { sequence } from "@sveltejs/kit/hooks"; import { client } from "$lib/server/auth"; @@ -79,7 +76,7 @@ import { options } from "$lib/auth"; const { createServerRequestAuth, createAuthRouteHook } = serverAuth( client, - options + options, ); const createServerAuthClient: Handle = ({ event, resolve }) => { @@ -100,14 +97,14 @@ const authRouteHandlers: AuthRouteHandlers = { export const handle = sequence( createServerAuthClient, - createAuthRouteHook(authRouteHandlers) + createAuthRouteHook(authRouteHandlers), ); ``` \* If you use typescript you need to update `Locals` type with `auth` so that auth is correctly recognized throughout the project: ```ts -import type { ServerRequestAuth } from "@edgedb/auth-sveltekit/server"; +import type { ServerRequestAuth } from "@gel/auth-sveltekit/server"; declare global { namespace App { @@ -135,7 +132,7 @@ In any of them you can define what to do in case of success or error. Every hand ### UI -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. +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** @@ -154,7 +151,7 @@ To help with implementing your own custom auth UI, the `auth` object has a numbe - `emailPasswordResetPassword(data: { reset_token: string; password: string } | FormData)` - `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 diff --git a/packages/auth-sveltekit/src/client.ts b/packages/auth-sveltekit/src/client.ts index 7d77a3ac4..d0575f3f7 100644 --- a/packages/auth-sveltekit/src/client.ts +++ b/packages/auth-sveltekit/src/client.ts @@ -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 AuthOptions { baseUrl: string; @@ -23,9 +23,9 @@ export function getConfig(options: AuthOptions) { return { baseUrl, authRoutesPath, - 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, authRoute: `${baseUrl}/${authRoutesPath}`, diff --git a/packages/auth-sveltekit/src/server.ts b/packages/auth-sveltekit/src/server.ts index 253e98c1d..9c918b14e 100644 --- a/packages/auth-sveltekit/src/server.ts +++ b/packages/auth-sveltekit/src/server.ts @@ -4,7 +4,7 @@ import { type RequestEvent, type Handle, } from "@sveltejs/kit"; -import type { Client } from "edgedb"; +import type { Client } from "gel"; import { Auth, builtinOAuthProviderNames, @@ -16,11 +16,11 @@ import { PKCEError, InvalidDataError, OAuthProviderFailureError, - EdgeDBAuthError, + GelAuthError, MagicLinkFailureError, type AuthenticationResponseJSON, type RegistrationResponseJSON, -} from "@edgedb/auth-core"; +} from "@gel/auth-core"; import { ClientAuth, getConfig, @@ -28,7 +28,7 @@ import { type AuthOptions, } from "./client.js"; -export * from "@edgedb/auth-core/errors"; +export * from "@gel/auth-core/errors"; export type { TokenData, AuthOptions, Client }; export type BuiltinProviderNames = @@ -574,7 +574,7 @@ async function handleAuthRoutes( if (error) { const desc = searchParams.get("error_description"); return onBuiltinUICallback({ - error: new EdgeDBAuthError(error + (desc ? `: ${desc}` : "")), + error: new GelAuthError(error + (desc ? `: ${desc}` : "")), }); } const code = searchParams.get("code");