Skip to content

Commit

Permalink
Fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
mpgxvii committed Oct 14, 2024
1 parent ae18d88 commit c364a4a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
1 change: 0 additions & 1 deletion pages/fitbit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ const Fitbit: NextPage = () => {
const traits = data?.identity?.traits
setTraits(traits)
setProjects(traits.projects) //

})
}, [flowId, router, router.isReady, returnTo])

Expand Down
29 changes: 21 additions & 8 deletions services/rest-source-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ export class RestSourceClient {
private readonly FRONTEND_ENDPOINT = `${publicRuntimeConfig.restSourceFrontendEndpoint}`
private readonly SOURCE_TYPE = "Oura"

async getRestSourceUser(accessToken: string, project: any): Promise<string | null> {
async getRestSourceUser(
accessToken: string,
project: any,
): Promise<string | null> {
try {
const response = await fetch(this.USER_ENDPOINT, {
method: "POST",
Expand All @@ -34,13 +37,14 @@ export class RestSourceClient {
console.warn("User already exists:", data.message)
return data.user.id
} else {
throw new Error(`Failed to create user: ${data.message || response.statusText}`)
throw new Error(
`Failed to create user: ${data.message || response.statusText}`,
)
}
}

const userDto = await response.json()
return userDto.id

} catch (error) {
console.error(error)
return null
Expand All @@ -67,7 +71,9 @@ export class RestSourceClient {
})

if (!response.ok) {
throw new Error(`Failed to retrieve access token: ${response.statusText}`)
throw new Error(
`Failed to retrieve access token: ${response.statusText}`,
)
}

const data = await response.json()
Expand Down Expand Up @@ -105,7 +111,10 @@ export class RestSourceClient {
window.location.href = authUrl
}

async getRestSourceAuthLink(accessToken: string, project: any): Promise<string | null> {
async getRestSourceAuthLink(
accessToken: string,
project: any,
): Promise<string | null> {
try {
const userId = await this.getRestSourceUser(accessToken, project)
if (!userId) {
Expand All @@ -125,7 +134,9 @@ export class RestSourceClient {
})

if (!response.ok) {
throw new Error(`Failed to retrieve registration token: ${response.statusText}`)
throw new Error(
`Failed to retrieve registration token: ${response.statusText}`,
)
}

const data = await response.json()
Expand All @@ -134,14 +145,16 @@ export class RestSourceClient {
}

return `${this.FRONTEND_ENDPOINT}/users:auth?token=${data.token}&secret=${data.secret}`

} catch (error) {
console.error(error)
return null
}
}

async redirectToRestSourceAuthLink(accessToken: string, project: any): Promise<void> {
async redirectToRestSourceAuthLink(
accessToken: string,
project: any,
): Promise<void> {
const url = await this.getRestSourceAuthLink(accessToken, project)
if (url) {
console.log("Redirecting to: ", url)
Expand Down

0 comments on commit c364a4a

Please sign in to comment.