---
# System prepended metadata

title: 2023-07-11 UserRoles + authentication

---

# Roles
- user
- betatester
- vip
- employee 
- franchise
- admin
- developer

User can belong to none, one, or several groups

```

/me

{
  "data": {
    "firstName": "name",
    "lastName": "lastName",
    "cognitoId": "cognitoId",
    "email": "email@gmail.com",
    "role": [
      "user",
      "betaTester",
      "developer",
      "admin"
    ]
  },
  "success": true
}

```


# Current use cases

## AdminUI

**TBD: Do we need a proxy between adminUI and services to verify permissions?**

AdminUI used through web-app and will use multiple services
- AWS
- Hygraph
- Rudderstack
- hubspot?

Login: 
- Can we use the current login method? (phonenumber + otp) -> 'custom:platform':"Admin" ?
```
export const signIn = async (phone: string): Promise<IAuthResponse> =>
  await Auth.signIn({
    username: phone,
    attributes: {
      'custom:platform': Platform.OS
    }
  });
```    



- Initial need for roles, only users with following roles can login:
    - franchise
    - developer
    - admin

AdminUI Views:
- AdminApp will handle what views users can see with what roles
- AdminApp views (most data requested from hygraph for now):
    - Locations, coupons, campaings, products, staticpages...
        - data from hygraph
    - Analytics/statistics
        - data from rudderstack/steve
    - Users
        - data from aws/hubspot(?)
        - editing userdata needs admin role at aws endpoint




---


## Application FE
### 1. Homescreen

in future might have more boxes depending on user roles

```
if user.roles.has('betatester')
    show assignment box
```
        
### 2. Coupons

- userRole field added to hygraph
- Show different coupons depending on user roles (more filtering)
- many to many comparison:
    
```
if user.roles.some(item => coupon.userRole.includes(item))
    show coupon
```

gql query:
    
```

query GetCouponsByType($active: Boolean, $type: CouponType, $lang: Locale!) {
coupons(
    where: { active: $active, type: $type }
    orderBy: order_ASC
    locales: [$lang, en]
    first: 100
) {
    couponId
    type
    title
    couponImage {
      url
    }
    longDescription {
      html
    }
    exceptions
    priceView
    singleUse
    posReply
    theme
    userRole
  }
}

```
    
response:
    
```
 ... 
    "theme": {
      "type": "",
      "theme": "",
      "background-color": "",
      "background-image": ""
    },
    "userRole": [
      "user",
      "admin"
    ]

```
    
    

    


