You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+84-8Lines changed: 84 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,10 @@
1
1
# GraphQL Authentication
2
2
3
-
**Work in progress, do not use yet**
3
+
_Previously called Prisma Auth_
4
4
5
5
A very opinionated user authentication package for [GraphQL](https://graphql.org/). It uses old-school email/password authentication.
6
6
7
-
This package does not access your data layer (e.g. an ORM); for that you need to write a_adapter_ (which is not hard to do).
7
+
This package provides **a GraphQL schema and GraphQL resolvers** for everything you need related to authentication. It does not access your data layer (e.g. an ORM); for that you need to write an_adapter_ (which is not hard to do).
8
8
If you use Prisma, there is already an adapter for you, **[graphql-authentication-prisma](https://github.com/Volst/graphql-authentication/tree/master/packages/graphql-authentication-prisma)**.
9
9
10
10
**Features:**
@@ -19,7 +19,7 @@ If you use Prisma, there is already an adapter for you, **[graphql-authenticatio
19
19
20
20
# Motivation
21
21
22
-
Adding user authentication seems simple; there are lots of examples on how to write a "login" and a "signup" resolver. You implement it in your own project and continue working. After a while you'll have users forgetting their password so you need to build something for that. Then you want to be able to invite users, ... you get the idea. After a while you have a lot of boilerplate code related to user authentication.
22
+
Adding user authentication seems simple; there are lots of examples on how to write a "login" and a "signup" resolver. You implement it in your own project and continue working. After a while you'll have users forgetting their password so you need to build something for that. Then you want to be able to invite users, ... you get the idea. In the end you have a lot of boilerplate code related to user authentication.
23
23
24
24
The intention with this package is **to let you write as less user-related code as possible**, while being flexible enough to support different use cases like open sign up, invitation-only signup, extra fields on the User model etc.
25
25
@@ -36,16 +36,80 @@ npm i graphql-authentication email-templates
36
36
37
37
# Usage
38
38
39
+
## Using the schema
40
+
41
+
In your own GraphQL schema you can import all the types this package provides:
42
+
43
+
```graphql
44
+
# import Query.*, Mutation.* from "node_modules/graphql-authentication/schema.graphql"
45
+
```
46
+
47
+
> This only works if you use [graphql-import](https://github.com/prismagraphql/graphql-import). If you are using graphql-yoga this will work out of the box!
48
+
49
+
Alternatively you can only import the types you want to expose, for example:
50
+
51
+
```graphql
52
+
# import Query.currentUser, Mutation.signupByInvite, Mutation.inviteUser, Mutation.login from "node_modules/graphql-authentication/schema.graphql"
53
+
```
54
+
55
+
## Configuration
56
+
57
+
We need to add some configuration to get this package to work. The following example uses [graphql-yoga](https://github.com/graphcool/graphql-yoga/), but it should also work with Apollo Server.
Lastly, this project can optionally send emails for you (e.g. the password reset link). [`email-templates`](https://www.npmjs.com/package/email-templates) is used for this. Be sure to configure it in the options:
However, this package does not provide the email templates itself for you, since these differ too much. You can [**copy the email templates**](./example/emails) from our example to get started.
An adapter sits between GraphQL Authentication and your own ORM/database thingy. If you are using Prisma, there is already [graphql-authentication-prisma](https://github.com/Volst/graphql-authentication/tree/master/packages/graphql-authentication-prisma) for you.
259
+
260
+
However, if you don't use Prisma, that's totally fine! Writing an adapter shouldn't take very long.
261
+
262
+
In [the tests](https://github.com/Volst/prisma-auth/blob/refactor/packages/graphql-authentication/src/__tests__/setup.ts) there is a good example of an adapter.
263
+
264
+
You can keep the adapter class directly in your own project, make a separate npm package for it or write a PR to add it here (please do)!
Copy file name to clipboardExpand all lines: packages/graphql-authentication-prisma/README.md
+8-41Lines changed: 8 additions & 41 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,58 +15,25 @@ npm i graphql-authentication graphql-authentication-prisma email-templates
15
15
16
16
## Step 1
17
17
18
-
In your Prisma `datamodel.graphql` file, add this [User model](./example/datamodel.graphql).
18
+
Read the [Usage](https://github.com/Volst/graphql-authentication/blob/master/README.md#usage) section in the full documentation first.
19
19
20
20
## Step 2
21
21
22
-
In your `schema.graphql` for your own server, add something like the following (you can also import specific endpoints only):
23
-
24
-
```graphql
25
-
# import Query.*, Mutation.* from "node_modules/graphql-authentication/schema.graphql"
26
-
```
27
-
28
-
## Step 3
29
-
30
-
In your server we now need to map these types to resolvers and pass in some options. The following example uses [graphql-yoga](https://github.com/graphcool/graphql-yoga/), but it should also work with Apollo Server.
22
+
After configuring the basics, you can now add this package as an adapter. Pseudo-code example:
0 commit comments