Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
poolsar42 committed Jun 5, 2023
1 parent ee32a14 commit f53f622
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 17 deletions.
2 changes: 1 addition & 1 deletion apps/console/app/routes/apps/$clientId/team.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export const action: ActionFunction = getRollupReqFunctionErrorWrapper(
)

export default () => {
useConnectResult(['SUCCESS', 'ACCOUNT_CONNECT_ERROR', 'CANCEL', 'ALREADY_CONNECTED_ERROR'])
useConnectResult()

const submit = useSubmit()

Expand Down
2 changes: 1 addition & 1 deletion apps/passport/app/routes/authorize.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ export default function Authorize() {
const navigate = useNavigate()
const transition = useTransition()

useConnectResult(['ACCOUNT_CONNECT_ERROR', 'CANCEL', 'ALREADY_CONNECTED_ERROR'])
useConnectResult()

const cancelCallback = () => {
const redirectURL = new URL(redirectUri)
Expand Down
3 changes: 1 addition & 2 deletions apps/passport/app/routes/connect/$address/sign.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export const action: ActionFunction = getRollupReqFunctionErrorWrapper(
async ({ request, context, params }) => {
const appData = await getAuthzCookieParams(request, context.env)
const jwt = await getUserSession(request, context.env, params.clientId)
const accountURN = parseJwt(jwt).sub! as AccountURN

const { address } = params
if (!address)
Expand Down Expand Up @@ -81,8 +80,8 @@ export const action: ActionFunction = getRollupReqFunctionErrorWrapper(


if (appData?.rollup_action === 'connect' && existing) {
const accountURN = parseJwt(jwt).sub! as AccountURN
if (accountURN === accountURNFromAddress) {
console.log({SOMETHIN: "WENT TERRIBLY WRONG"})
return redirect(getAuthzRedirectURL(appData, 'ALREADY_CONNECTED_ERROR'))
}
return redirect(getAuthzRedirectURL(appData, 'ACCOUNT_CONNECT_ERROR'))
Expand Down
25 changes: 14 additions & 11 deletions apps/passport/app/utils/authenticate.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { AddressURNSpace } from '@proofzero/urns/address'
import type { AddressURN } from '@proofzero/urns/address'
import type { AccountURN } from '@proofzero/urns/account'

import { JsonError } from '@proofzero/utils/errors'
import { GrantType, ResponseType } from '@proofzero/types/access'

import {
Expand All @@ -13,6 +12,7 @@ import {
import {
createUserSession,
getAuthzCookieParamsSession,
getUserSession,
parseJwt,
} from '~/session.server'
import { generateGradient } from './gradient.server'
Expand Down Expand Up @@ -40,15 +40,25 @@ export const authenticateAddress = async (
})
}

const jwt = await getUserSession(request, env, appData?.clientId)
if (
appData.rollup_action &&
['connect', 'reconnect'].includes(appData?.rollup_action)
) {
let result = undefined

if (existing && appData.rollup_action === 'connect') {
const loggedInAccount = parseJwt(jwt).sub
if (account !== loggedInAccount) {
result = 'ACCOUNT_CONNECT_ERROR'
} else {
result = 'ALREADY_CONNECTED_ERROR'
}
}

const redirectURL = getAuthzRedirectURL(
appData,
existing && appData.rollup_action === 'connect'
? 'ACCOUNT_CONNECT_ERROR'
: undefined
result
)

return redirect(redirectURL)
Expand Down Expand Up @@ -108,13 +118,6 @@ export const getAuthzRedirectURL = (

redirectURL += `?${urlParams}`

console.log({ redirectURL })
console.log({ redirectURL })
console.log({ redirectURL })
console.log({ redirectURL })
console.log({ redirectURL })


return redirectURL
}

Expand Down
11 changes: 9 additions & 2 deletions packages/design-system/src/hooks/useConnectResult.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import { ToastType, toast } from '../atoms/toast'
import { useEffect } from 'react'

export default (
handledMessageTypes: string[] = ['SUCCESS', 'ACCOUNT_CONNECT_ERROR', 'CANCEL']
handledMessageTypes: string[] = [
'SUCCESS',
'ACCOUNT_CONNECT_ERROR',
'ALREADY_CONNECTED_ERROR',
'CANCEL'
]
) => {
useEffect(() => {
const url = new URL(window.location.href)
Expand Down Expand Up @@ -31,9 +36,11 @@ export default (
toast(
ToastType.Error,
{
message: 'Account is already connected to your identity.' },
message: 'Account is already connected to your identity.'
},
{ duration: 2000 }
)
break
case 'CANCEL':
toast(
ToastType.Warning,
Expand Down

0 comments on commit f53f622

Please sign in to comment.