Skip to content

Commit 28c4049

Browse files
authored
Update auth0.md
Address PR comments
1 parent 3cd733e commit 28c4049

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

docs/guides/authentication/auth0.md

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ sidebar_label: 🚧 Auth0
77
# Integrating With Auth0
88

99

10-
This guide aims to give some simple examples of using Auth0 to provide authentication when used in conjunction with Zenstack. It will not take into account the different types of authentication that Auth0 offers. The premise is that you have and understanding of Auth0's method of authentication and are able to produce an object as a result of authenticating a user with Auth0.
10+
This guide aims to give some simple examples of using Auth0 to provide authentication when used in conjunction with ZenStack. It will not take into account the different types of authentication that Auth0 offers. The premise is that you have and understanding of Auth0's method of authentication and are able to produce an object as a result of authenticating a user with Auth0.
1111

1212
## Enhancing the prisma client
1313

14-
The basic premise of applying a custom session object to Zenstack.
14+
The basic premise of applying a custom session object to ZenStack.
1515

1616
Create a user object and provide it to the enhance function when creating the Prisma client.
1717

18-
```
18+
```ts
1919
export const getPrisma = async (req) => {
2020
const user = await getAuthenticatedAuth0User(req);
2121
return enhance(user);
@@ -24,8 +24,7 @@ export const getPrisma = async (req) => {
2424

2525
You can provide a type in the ZModel to express what the contents of the user object is.
2626

27-
```
28-
27+
```prisma
2928
type Auth {
3029
id String @id
3130
specialKey String
@@ -35,11 +34,11 @@ type Auth {
3534

3635
## Adding Auth0 authentication
3736

38-
You can authenticate an Auth0 user and extract information from the authentication and apply is to the Zenstack session.
37+
You can authenticate an Auth0 user and extract information from the authentication and apply it to the ZenStack session.
3938

4039
Here's an example using a JWT:
4140

42-
```
41+
```ts
4342
export const getPrismaJWT = async (req) => {
4443
try {
4544
const jwks = jose.createRemoteJWKSet(new URL(process.env.AUTH0_JWKS_URI));
@@ -65,13 +64,13 @@ export const getPrismaJWT = async (req) => {
6564
6665
This would populate your `auth()` in the Zmodel with the object you've just created from auth0; enabling checks like:
6766
68-
```
67+
```prisma
6968
@@allow('read, update, create', auth().id == this.id)
7069
```
7170
7271
or
7372
74-
```
73+
```prisma
7574
@@allow('read, update, create', auth().specialKey == 'SUPERMAN')
7675
```
7776
@@ -84,12 +83,12 @@ You may want to keep a record of User's in your own database.
8483
8584
You can create your application in such a way that a lack of the user existing in the managed database triggers a process to create one, such as a user onboarding flow.
8685
87-
```
86+
```ts
8887
const currentUser = async (req) => {
8988
const session = await getSession(req); // get your auth0 auth session
9089

9190
if (!session?.user.sub) {
92-
throw new Error('UNAUTHENTICATED'); // Throw an error if the user isn's authenticated
91+
throw new Error('UNAUTHENTICATED'); // Throw an error if the user isn't authenticated
9392
}
9493

9594
const dbUser = await prisma.user.findUnique({ // Find the user in the db
@@ -111,9 +110,9 @@ export const getPrisma = async (req) => {
111110
112111
When the client is created, the database is queried using the contents of the Auth0 token.
113112
114-
In this case, the Auth tyoe is what provide authentication, not the User model, for example:
113+
In this case, the Auth type is what provide authentication, not the User model, for example:
115114
116-
```
115+
```prisma
117116
// Specify the auth type
118117
type Auth {
119118
id String @id

0 commit comments

Comments
 (0)