-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add low-level auth lib + nextjs integration (#750)
* Add low-level auth lib * Add nextjs app router integration + example (wip) * Update route handlers to take params object + add missing apis + fix some bugs * Refactor and add initial next pages integration * Add basic readme + mark version as alpha * Drop nextjs example * Fix lint * Split into two packages * Update readme's * Fix readme code example * Address review feedback * Build workspaces in the right order * Update `getProvidersInfo` query * Replace emailpassword provider magic string with generated const
- Loading branch information
Showing
22 changed files
with
1,599 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"'); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 <[email protected]>", | ||
"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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; |
Oops, something went wrong.