|
| 1 | +### Fauna Superprofile Saas Setup |
| 2 | +To access the Admin section which includes the Event Create Menu, there would be a need to setup the Superprofile, currently we use FaunaDB for handling this. |
| 3 | +Follow this [link](https://graphql.workshops.fauna.com/building/build-with-nextjs/client-setup/#creating-a-front-end-role) instructions to get the Fauna key, then paste it in the `.env` as: |
| 4 | +``` |
| 5 | +NEXT_PUBLIC_FAUNA_SECRET="your private key" |
| 6 | +``` |
| 7 | +To get more familiar with Fauna here is a quick short [workshop link](https://graphql.workshops.fauna.com/getting-started/) |
| 8 | + |
| 9 | +Or here is a quick guide to get started with Fauna: |
| 10 | +1. Head to [dashboard.fauna.com](https://dashboard.fauna.com/), if you are logged in, click __CREATE DATABASE__, choose the US server. |
| 11 | +<img width="356" alt="image" src="https://user-images.githubusercontent.com/61188295/178947597-158a4c05-3c92-4ba6-87df-c3a808f79134.png"> |
| 12 | +2. In the left section click the __GraphQL__ and then __IMPORT SCHEMA__; schema to be uploaded is located in `../assets/rc4community-schema.graphql`. |
| 13 | +3. Go to the __Functions__ tab, there will be two functions, in the UpserUser, replace it with the following function code. |
| 14 | +<details> |
| 15 | +<summary>UpsertUser function</summary> |
| 16 | + |
| 17 | +``` |
| 18 | +Query( |
| 19 | + Lambda( |
| 20 | + ["uid", "email", "displayName", "phoneNumber", "photoURL"], |
| 21 | + Let( |
| 22 | + { |
| 23 | + user: Match(Index("getByEmail"), Var("email")), |
| 24 | + upsert: If( |
| 25 | + Exists(Var("user")), |
| 26 | + Update(Select(["ref"], Get(Var("user"))), { |
| 27 | + data: { |
| 28 | + displayName: Var("displayName"), |
| 29 | + phoneNumber: Var("phoneNumber"), |
| 30 | + photoURL: Var("photoURL") |
| 31 | + } |
| 32 | + }), |
| 33 | + Create(Collection("User"), { |
| 34 | + data: { |
| 35 | + uid: Var("uid"), |
| 36 | + email: Var("email"), |
| 37 | + displayName: Var("displayName"), |
| 38 | + phoneNumber: Var("phoneNumber"), |
| 39 | + photoURL: Var("photoURL") |
| 40 | + } |
| 41 | + }) |
| 42 | + ) |
| 43 | + }, |
| 44 | + Var("upsert") |
| 45 | + ) |
| 46 | + ) |
| 47 | +) |
| 48 | +``` |
| 49 | +</details> |
| 50 | + |
| 51 | +4. Under the __Security__ tab click on __NEW KEY__ no need to modify anything, go with defaults, then hit the __SAVE__, copy the _KEY'S SECRET_ and paste it in the `.env` as: |
| 52 | +``` |
| 53 | +NEXT_PUBLIC_FAUNA_SECRET="your key's secret" |
| 54 | +NEXT_PUBLIC_FAUNA_DOMAIN="https://graphql.us.fauna.com/graphql" |
| 55 | +
|
| 56 | +``` |
| 57 | +5. Create the first basic user using the __GraphQL__ tab, following is the mutation schema of a GraphQL query to create a user |
| 58 | +``` |
| 59 | +mutation { |
| 60 | + createUser(data: { |
| 61 | + displayName: "YOUR_NAME" |
| 62 | + email: "NEXT_PUBLIC_EVENT_ADMIN_MAIL" |
| 63 | + uid: "ANY_UNIQUE_NUMBER" |
| 64 | + events: { |
| 65 | + create: { |
| 66 | + role: "Admin" |
| 67 | + email: "NEXT_PUBLIC_EVENT_ADMIN_MAIL" |
| 68 | + } |
| 69 | + } |
| 70 | + }) { |
| 71 | + _id |
| 72 | + displayName |
| 73 | + } |
| 74 | +} |
| 75 | +``` |
| 76 | + |
| 77 | +6. Congrats! and thank you! for reading this. With this you are all set, to access Admin menus. |
0 commit comments