Skip to content

Commit 150db0c

Browse files
committed
feat(auth): add edgedb:auth:callback
1 parent a1c13c2 commit 150db0c

8 files changed

Lines changed: 299 additions & 114 deletions

File tree

.github/thecompaniesapi.png

3.1 KB
Loading

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,4 @@ Temporary Items
6060
**/dbschema/queries.*
6161
**/dbschema/query-builder
6262
**/queries/*.edgeql.ts
63+
**/dbschema/interfaces.ts

README.md

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,19 @@ That's it! Your Nuxt project now has a database. ✨
4545

4646
If you do not already have [EdgeDB](https://www.edgedb.com) installed on your machine, the install wizard will help you to install it.
4747

48+
## Example project
49+
50+
If you want to run the example project, you have to git clone this repository and run the playground.
51+
52+
As EdgeDB cannot run on web containers environment like Stackblitz or CodeSandbox, you must clone the project locally to run this playground.
53+
54+
```bash
55+
git clone git@github.com:Tahul/nuxt-edgedb.git
56+
cd nuxt-edgedb
57+
pnpm install
58+
cd playground && pnpm run dev
59+
```
60+
4861
## Server usage
4962

5063
The module provides auto-imported composables available anywhere inside `server/` context of your Nuxt app.
@@ -443,7 +456,31 @@ NUXT_EDGEDB_AUTH_VERIFY_REDIRECT_URL=http://localhost:3000/auth/verify
443456

444457
EdgeDB Auth only provides bare minimal identity feature for authentication.
445458

446-
In the code example I provided, I added a `User` type that goes along with the `Identity` interface.
459+
In the code example provided for authentication setup, a `User` type goes along with the `Identity` interface.
460+
461+
If you want to fill `User` with other attributes upon user registration, you will have to implement this behavior.
462+
463+
The initial authentication workflow is made to be as minimal as possible so anyone can build any kind of authentication and roles system on top of it.
464+
465+
If you want to resolve data from OAuth providers, you can use the Nitro hook called `edgedb:auth:callback` from a Nitro plugin.
466+
467+
```
468+
// server/plugins/auth.ts
469+
470+
export default defineNitroPlugin((app) => {
471+
app.hooks.hook('edgedb:auth:callback', (data) => {
472+
const {
473+
code,
474+
verifier,
475+
codeExchangeUrl,
476+
codeExchangeResponseData,
477+
} = data
478+
479+
// codeExchangeResponseData contains the OAuth token from the provider.
480+
// ... implement your own authentication logic.
481+
})
482+
})
483+
```
447484

448485
## Production
449486

@@ -516,6 +553,7 @@ No, as they are generated with your Nuxt client, you should add them to your `.g
516553
**/*.edgeql.ts
517554
dbschema/queries.*
518555
dbschema/query-builder
556+
dbschema/interfaces.ts
519557
queries/*.query.ts
520558
```
521559

@@ -543,6 +581,12 @@ It seem to be taken by [`ohmree`](https://github.com/ohmree), but the package se
543581

544582
If anyone happens to know him, I would be happy to get in contact!
545583

584+
### Contributions
585+
586+
There is still plenty of great features to build for this integration.
587+
588+
I would be happy to receive and review any Pull Request.
589+
546590
## Development
547591

548592
```bash
@@ -569,6 +613,10 @@ npm run test:watch
569613
npm run release
570614
```
571615

616+
## Sponsors
617+
618+
[![thecompaniesapi.com](./.github/thecompaniesapi.png)](https://thecompaniesapi.com)
619+
572620
<!-- Badges -->
573621
[npm-version-src]: https://img.shields.io/npm/v/nuxt-edgedb-module/latest.svg?style=flat&colorA=18181B&colorB=28CF8D
574622
[npm-version-href]: https://npmjs.com/package/nuxt-edgedb-module

playground/dbschema/default.esdl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,9 @@ module default {
2929
required author: User {
3030
default := global current_user;
3131
};
32-
3332
access policy author_has_full_access
3433
allow all
3534
using (.author ?= global current_user);
36-
3735
access policy others_read_only
3836
allow select;
3937
}

0 commit comments

Comments
 (0)