Skip to content
Closed
Show file tree
Hide file tree
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
94 changes: 72 additions & 22 deletions packages/identity-service/src/authMiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,68 @@
const audiusLibsWrapper = require('./audiusLibsInstance')
const { encodeHashId, decodeHashId } = require('./utils/hashIds')

const SDK_USER_LOOKUP_TIMEOUT_MS = 3000

const withTimeout = (promise, ms, message) => {
let timeoutId
const timeout = new Promise((_resolve, reject) => {
timeoutId = setTimeout(() => reject(new Error(message)), ms)
})

return Promise.race([

Check failure on line 22 in packages/identity-service/src/authMiddleware.js

View workflow job for this annotation

GitHub Actions / Identity Lint

Replace `⏎····promise,⏎····timeout⏎··` with `promise,·timeout`
promise,
timeout
]).finally(() => clearTimeout(timeoutId))
}

const getUserAccountForWallet = async ({
req,
walletAddress,
encodedDataMessage,
signature
}) => {
const audiusSdk = req.app.get('audiusSdk')
const usersApi = audiusSdk?.users ?? audiusSdk?.full?.users

if (!usersApi) {
throw new Error('Audius SDK users API is unavailable')
}

return withTimeout(
usersApi.getUserAccount({
wallet: walletAddress,
encodedDataMessage,
encodedDataSignature: signature
}),
SDK_USER_LOOKUP_TIMEOUT_MS,
'audiusSdk.users.getUserAccount timed out'
)
}

const backfillUserFromAccount = async ({
req,
user,
walletAddress,
encodedDataMessage,
signature
}) => {
const res = await getUserAccountForWallet({
req,
walletAddress,
encodedDataMessage,
signature
})
const accountUser = res.data.user
const userId = decodeHashId(accountUser.id)
const handle = accountUser.handle

return user.update({
blockchainUserId: userId,
handle,
isGuest: !handle
})
}

/**
* Queries for whether the wallet address has privilege to act as actingUserId
* @param {number} managerWalletAddress
Expand Down Expand Up @@ -114,18 +176,12 @@
// ensuring that the user.handle always represents the latest state on chain
if (!user.blockchainUserId || !user.handle) {
try {
const res = await req.app.get('audiusSdk').full.users.getUserAccount({
wallet: walletAddress,
user = await backfillUserFromAccount({
req,
user,
walletAddress,
encodedDataMessage,
encodedDataSignature: signature
})
const discprovUser = res.data.user
const userId = decodeHashId(discprovUser.id)
const handle = discprovUser.handle
user = await user.update({
blockchainUserId: userId,
handle,
isGuest: !handle
signature
})
} catch (e) {
req.logger.error(e, 'Failed to update blockchainUserId/handle')
Expand Down Expand Up @@ -181,18 +237,12 @@

if (!user.blockchainUserId || !user.handle) {
try {
const res = await req.app.get('audiusSdk').full.users.getUserAccount({
wallet: walletAddress,
user = await backfillUserFromAccount({
req,
user,
walletAddress,
encodedDataMessage,
encodedDataSignature: signature
})
const discprovUser = res.data.user
const userId = decodeHashId(discprovUser.id)
const handle = discprovUser.handle
user = await user.update({
blockchainUserId: userId,
handle,
isGuest: !handle
signature
})
} catch (e) {
req.logger.error(e, 'Failed to update blockchainUserId/handle')
Expand Down
7 changes: 7 additions & 0 deletions packages/identity-service/src/routes/idSignals.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ module.exports = function (app) {
handleResponse(async (req) => {
const { blockchainUserId, handle } = req.user

if (!handle) {
req.logger.warn(
`idSignals | record_ip | Skipping IP record for user with id ${blockchainUserId} because handle is missing`
)
return successResponse()
}

try {
const userIP = getIP(req)
req.logger.info(
Expand Down
13 changes: 11 additions & 2 deletions packages/web/src/pages/sign-up-page/pages/LoadingAccountPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { useEffect } from 'react'

import {
selectIsAccountComplete,
useCurrentAccountUser
} from '@audius/common/api'
import { route } from '@audius/common/utils'
import { Flex } from '@audius/harmony'
import { useSelector } from 'react-redux'
Expand All @@ -26,10 +30,15 @@ export const LoadingAccountPage = () => {
const isFastReferral = useFastReferral()
const accountReady = useSelector(getAccountReady)
const accountCreationStatus = useSelector(getStatus)
const { data: hasCompleteAccount = false } = useCurrentAccountUser({
select: selectIsAccountComplete
})

const isAccountReady = isFastReferral
? accountReady
: accountReady || accountCreationStatus === EditingStatus.SUCCESS
? accountReady || hasCompleteAccount
: accountReady ||
hasCompleteAccount ||
accountCreationStatus === EditingStatus.SUCCESS

useEffect(() => {
if (isAccountReady) {
Expand Down
Loading