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

Add low-level auth lib + nextjs integration #750

Merged
merged 14 commits into from
Nov 8, 2023
Merged
5 changes: 4 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ jobs:

- name: Build
run: |
yarn workspaces run build
yarn workspace edgedb build
yarn workspace @edgedb/auth-core build
yarn workspace @edgedb/auth-nextjs build
yarn workspace @edgedb/generate build

# - name: Compile for Deno
# run: |
Expand Down
47 changes: 47 additions & 0 deletions packages/auth-core/genConsts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const fs = require("node:fs/promises");
const { createClient } = require("edgedb");

const client = createClient("_localdev");

(async function () {
const providerNames = await client.queryRequiredSingle(`
with
oauth_providers := (
select schema::ObjectType
filter .bases.name = 'ext::auth::OAuthProviderConfig'
),
emailpassword_provider := (
select schema::ObjectType
filter .name = 'ext::auth::EmailPasswordProviderConfig'
)
select {
oauth := (
select oauth_providers.properties filter .name = 'name'
).default,
emailpassword := assert_single((
select emailpassword_provider.properties filter .name = 'name'
).default)
}`);

await fs.writeFile(
"./src/consts.ts",
`// AUTOGENERATED - Run \`yarn gen-consts\` to re-generate.

export const builtinOAuthProviderNames = [
${providerNames.oauth
.sort()
.map((provider) => ` ${provider.replace(/^'|'$/g, '"')},`)
.join("\n")}
] as const;
export type BuiltinOAuthProviderNames =
(typeof builtinOAuthProviderNames)[number];

export const emailPasswordProviderName = ${providerNames.emailpassword.replace(
/^'|'$/g,
'"'
)};
`
);

console.log('Generated into "src/consts.ts"');
})();
7 changes: 7 additions & 0 deletions packages/auth-core/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
preset: "ts-jest",
testEnvironment: "node",
testPathIgnorePatterns: ["./dist"],
globalSetup: "./test/globalSetup.ts",
globalTeardown: "./test/globalTeardown.ts",
};
37 changes: 37 additions & 0 deletions packages/auth-core/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "@edgedb/auth-core",
"description": "Core helper library for the EdgeDB Auth extension",
"version": "0.1.0-alpha.1",
"author": "EdgeDB <info@edgedb.com>",
"repository": {
"type": "git",
"url": "https://github.com/edgedb/edgedb-js.git",
"directory": "packages/auth-core"
},
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"license": "Apache-2.0",
"sideEffects": false,
"files": [
"/dist"
],
"scripts": {
"test": "jest --detectOpenHandles",
"build": "tsc --project tsconfig.json",
"gen-consts": "node genConsts.js"
},
"devDependencies": {
"@types/node": "^20.8.4",
"edgedb": "^1.3.6",
"typescript": "5.0.4",
"@types/jest": "^29.5.2",
"jest": "29.5.0",
"ts-jest": "29.1.0"
},
"peerDependencies": {
"edgedb": "^1.3.6"
},
"dependencies": {
"jwt-decode": "^3.1.2"
}
}
10 changes: 10 additions & 0 deletions packages/auth-core/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# @edgedb/auth-core: Core helper library for the EdgeDB Auth extension

> 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.

This library contains some low-level utilities to help working with the EdgeDB auth extension; namely resolving the api endpoint urls from an edgedb `Client` object, providing wrappers around those api's to help handle the various auth flows (including handling PKCE), and adding typesafety.

It is recommended to instead use the separate helper libraries created to make integration with popular frameworks as easy as possible. Currently supported frameworks:

- Next.js (@edgedb/auth-nextjs)
- _...more coming soon_
12 changes: 12 additions & 0 deletions packages/auth-core/src/consts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// AUTOGENERATED - Run `yarn gen-consts` to re-generate.

export const builtinOAuthProviderNames = [
"builtin::oauth_apple",
"builtin::oauth_azure",
"builtin::oauth_github",
"builtin::oauth_google",
] as const;
export type BuiltinOAuthProviderNames =
(typeof builtinOAuthProviderNames)[number];

export const emailPasswordProviderName = "builtin::local_emailpassword";
Loading
Loading