Skip to content

Commit

Permalink
Use preferred language from the returned profile data
Browse files Browse the repository at this point in the history
  • Loading branch information
darh committed Sep 17, 2021
1 parent 463c26e commit ca9f1ea
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/plugins/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ interface OAuth2TokenResponse {
name?: string;
handle?: string;
email?: string;
preferred_language?: string;
}

interface PluginOpts {
Expand Down Expand Up @@ -277,13 +278,20 @@ export class Auth {

return this.axios.get(oauth2InfoURL, { headers }).then(({ data }) => {
this.log.info('data fetch form info endpoint', { oauth2InfoURL, headers, data })
this[user] = new system.User({

const authUser = new system.User({
userID: data.sub,
name: data.name,
email: data.email,
handle: data.username,
})

if (data.preferred_language) {
authUser.meta.preferredLanguage = data.preferred_language || 'en'
}

this[user] = authUser

return data
}).catch((error) => {
this.log.info('data fetch form info endpoint failed', { oauth2InfoURL, headers, error })
Expand Down Expand Up @@ -418,6 +426,10 @@ export class Auth {
email: oa2tkn.email,
})

if (oa2tkn.preferred_language) {
u.meta.preferredLanguage = oa2tkn.preferred_language
}

this[accessToken] = oa2tkn.access_token
this[user] = u

Expand Down

0 comments on commit ca9f1ea

Please sign in to comment.