Skip to content

Commit eba8ca3

Browse files
authored
community: clarify vuejs-auth0-graphql readme (hasura#4383)
1 parent 5d35f56 commit eba8ca3

2 files changed

Lines changed: 35 additions & 10 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dist/
2+

‎community/sample-apps/vuejs-auth0-graphql/app/README.md‎

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ To do this, open `auth_config.json`, and replace the values within with your own
102102
```
103103

104104
## Create the initial tables
105-
1. Add your database URL and admin secret in `hasura/config.yaml`
105+
1. Add your graphql URL (like https://your-app.herokuapp.com) and admin secret in `hasura/config.yaml`
106106

107107
```yaml
108108
endpoint: https://<hge-heroku-url>
@@ -113,21 +113,44 @@ admin_secret: <your-admin-secret>
113113

114114
## Create Auth0 Rule
115115

116-
Everytime user signups on Auth0, we need to sync that user into our postgres database. This is done using Auth0 rules. Create a Rule and insert the following code:
116+
Everytime a user signs up via Auth0, we need to sync that user into our postgres database. This is done using Auth0 rules.
117+
118+
### Add an Auth0 rule configuration value
119+
Go to https://manage.auth0.com/dashboard/us/your-auth0-app/rules and add a configuration value to the `Settings` section.
120+
121+
* Key: `x-hasura-admin-secret`
122+
* Value: your admin secret
123+
124+
## Create the Auth0 rule
125+
Create a Rule and insert the following code:
117126

118127
```
119128
function (user, context, callback) {
120-
const userId = user.user_id;
121-
const nickname = user.nickname;
129+
const mutation = `
130+
mutation ($id: String!, $email: String!) {
131+
insert_user(objects: [{
132+
id: $id,
133+
email: $email
134+
}]) {
135+
affected_rows
136+
}
137+
}`;
138+
139+
const variables = {
140+
id: user.user_id,
141+
email: user.email
142+
};
122143

144+
const body = { query: mutation, variables };
145+
123146
request.post({
124-
headers: {'content-type' : 'application/json', 'x-hasura-admin-secret': '<your-admin-secret>'},
125-
url: 'http://myapp.herokuapp.com/v1/graphql',
126-
body: `{\"query\":\"mutation($userId: String!, $nickname: String) {\\n insert_users(\\n objects: [{ auth0_id: $userId, name: $nickname }]\\n on_conflict: {\\n constraint: users_pkey\\n update_columns: [last_seen, name]\\n }\\n ) {\\n affected_rows\\n }\\n }\",\"variables\":{\"userId\":\"${userId}\",\"nickname\":\"${nickname}\"}}`
127-
}, function(error, response, body){
147+
headers: {'content-type': 'application/json', 'x-hasura-admin-secret': configuration['x-hasura-admin-secret']},
148+
url: 'https://your-app.herokuapp.com/v1/graphql',
149+
body: JSON.stringify(body)
150+
}, function(error, response, body) {
128151
console.log(body);
129-
callback(null, user, context);
130-
});
152+
callback(error, user, context);
153+
});
131154
}
132155
```
133156

0 commit comments

Comments
 (0)