1
0
Fork 0

feat(shared): Initial implementation of Oauth flow

This commit is contained in:
Joost De Cock 2023-09-01 18:30:24 +02:00
parent 70b8fdd703
commit 01ef6c9896
24 changed files with 1077 additions and 172 deletions

View file

@ -67,6 +67,15 @@ const responseHandler = (response, expectedStatus = 200, expectData = true) => {
return { success: true, response }
}
// Unpack axios errors
if (response.name === 'AxiosError')
return {
success: false,
status: response.response?.status,
data: response.response?.data,
error: response.message,
}
return { success: false, response }
}
@ -81,6 +90,20 @@ Backend.prototype.signUp = async function ({ email, language }) {
return responseHandler(await api.post('/signup', { email, language }), 201)
}
/*
* backend.oauthInit: Init Oauth flow for oauth provider
*/
Backend.prototype.oauthInit = async function ({ provider, language }) {
return responseHandler(await api.post('/signin/oauth/init', { provider, language }))
}
/*
* backend.oauthSignIn: User sign in via oauth provider
*/
Backend.prototype.oauthSignIn = async function ({ state, code, provider }) {
return responseHandler(await api.post('/signin/oauth', { state, code, provider }))
}
/*
* Backend.prototype.loadConfirmation: Load a confirmation
*/
@ -117,6 +140,13 @@ Backend.prototype.updateAccount = async function (data) {
return responseHandler(await api.patch(`/account/jwt`, data, this.auth))
}
/*
* Update consent (uses the jwt-guest middleware)
*/
Backend.prototype.updateConsent = async function (consent) {
return responseHandler(await api.patch(`/consent/jwt`, { consent }, this.auth))
}
/*
* Checks whether a username is available
*/