Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TikTok auth + improve association #4511

Merged
merged 3 commits into from
Dec 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions identity-service/src/routes/tiktok.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ module.exports = function (app) {
try {
// Fetch user's accessToken
const accessTokenResponse = await axios.post(urlAccessToken)
const { access_token: accessToken } = accessTokenResponse.data
const {
data: { access_token: accessToken }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good ol' data.data

} = accessTokenResponse.data

// Fetch TikTok user from the TikTok API
const userResponse = await axios.post(
Expand All @@ -90,15 +92,25 @@ module.exports = function (app) {

const { user: tikTokUser } = data

// Store the user id, and current profile for user in db
await models.TikTokUser.findOrCreate({
const existingTikTokUser = await models.TikTokUser.findOne({
where: { uuid: tikTokUser.open_id },
defaults: {
blockchainUserId: {
[models.Sequelize.Op.not]: null
}
})

if (existingTikTokUser) {
return errorResponseBadRequest(
`Another Audius profile has already been authenticated with TikTok user @${tikTokUser.display_name}!`
)
} else {
// Store the user id, and current profile for user in db
await models.TikTokUser.upsert({
uuid: tikTokUser.open_id,
profile: tikTokUser,
verified: tikTokUser.is_verified
}
})
})
}

return successResponse(accessTokenResponse.data)
} catch (err) {
Expand Down