Should allow user to signup/login quickly from GitHub without requiring any additional input.
Implementation:
The main backend access point for frontend would be the loginWithGithub Mutation. It's schema would be like
mutation loginWithGithub(code: String!) {
# Similar to normal `register` mutation
success: Boolean!
errors: [String!]
# login: LoginMutation -- edited
token: String
user: UserType
}
A new GithubAuthUser table will be defined with only a foreign key to the main Users table, and it's primary key as the github's user id.
The backend will use the oauth authorization code to get the github token
It will try to get the user's details with that token (the name, github's user id, and emails).
The github id will be matched against the table for GithubAuthUser. If the user exists, it will return that user.
If not, we will get the primary verified email of the user and validate that (mostly a check for uniqueness). I haven't exactly planned the frontend flow for when a user with that email already exists, but I think displaying an error with details would be appropriate.
If the email is available, a new user should be created with new_user=True and login_type='github', and a new GithubAuthUser will be created.
The new User will have a random readable username (with some username generator), a random password, and the user's primary verified email as email.
The new_user flag should be made False and login_type to both or github password when the user changes their username.
New TODOs:
[x] Add a postgres JSONField for login_types and make the login_types visible in a given format with a resolver
[x] Add a mutation for changing username of user which will toggle new_user to False.
[ ] Add "password": true to login_types when a password is set on the User. For this, override the User's default set_password method to send a password_changed signal.
[x] Add mutation to associate already existing user with a GitHub account.
Tasks:
Implementation:
loginWithGithub
Mutation. It's schema would be likeGithubAuthUser
table will be defined with only a foreign key to the main Users table, and it's primary key as the github's user id.GithubAuthUser
. If the user exists, it will return that user.new_user=True
andlogin_type='github'
, and a newGithubAuthUser
will be created.new_user
flag should be madeFalse
andlogin_type
toboth
orgithub password
when the user changes their username.New TODOs:
login_type
s and make the login_types visible in a given format with a resolvernew_user
to False."password": true
tologin_types
when a password is set on the User. For this, override the User's defaultset_password
method to send apassword_changed
signal.