WarwickAI / wai-platform

A platform for the management of Warwick AI events, including projects, talks and courses.
MIT License
1 stars 1 forks source link

Research data model #38

Open omarathon opened 3 years ago

omarathon commented 3 years ago

Specifically, how to get users into Amplify (current idea is table User in Amplify with trigger in Congito which adds them to the table), how to get them to the front-end (via GraphQL)

Edward-Upton commented 3 years ago

The code here could be a solution to this problem.

type User 
  @model 
  @auth(rules: [{ allow: owner, ownerField: "id", queries: null }]) {
  id: ID!
  username: String!
  conversations: [ConvoLink] @connection(name: "UserLinks")
  messages: [Message] @connection(name: "UserMessages")
    createdAt: String
    updatedAt: String
}

Here's a step by step explanation of how this would work:

  1. User logs in, Cognito handles authentication with Warwick.
  2. Once logged in, the user is redirected to warwick.ai.
  3. On redirection, the client will send a GraphQL mutation to create a new User item. The User model ensures that the user is actually logged in and will check they have a valid session using @auth. The logged-in user will have their id stored as the id in the User item, therefore subsequent login will not duplicate the item, just update it.
Edward-Upton commented 3 years ago

After some more research, I think we are better of just having a lambda function that will add a row to our DB (model called something like UserProfile) that will trigger on the Cognito after authentication/confirmation. This lambda function should also check if the user profile already exists first to avoid creating duplicates or removing old rows.

The UserProfile should store anything that we want to use in the platform e.g.: Attributes
Name
Username / Email
Credits / Coins
Position (member/exec)