Skip to content

Commit

Permalink
fix sign in (#297)
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-t-wang authored Oct 19, 2024
1 parent bc33a08 commit 4b03617
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
24 changes: 12 additions & 12 deletions src/pages/api/auth/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

import { NextApiRequest, NextApiResponse } from "next"
import { redirect } from "next/dist/server/api-utils"
import { redirect } from 'next/dist/server/api-utils'
import { NextApiRequest, NextApiResponse } from 'next'

export default async function handler(req: NextApiRequest, res: NextApiResponse) {
const url = new URL(req.url!, process.env.NEXT_PUBLIC_APP_URL)
Expand All @@ -10,16 +9,17 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)

// TODO: Properly generate and store temporary nonces to exemplify proper usage

if (!code) {
return redirect(res, `${process.env.NEXT_PUBLIC_APP_URL}/try-callback/?error=code_not_provided`)
if (!code) {
return redirect(res, `${process.env.NEXT_PUBLIC_APP_URL}/world-id/try-callback/?error=code_not_provided`)
}

if (!state) {
return redirect(res, `${process.env.NEXT_PUBLIC_APP_URL}/try-callback/?error=state_not_provided`)
}
return redirect(res, `${process.env.NEXT_PUBLIC_APP_URL}/world-id/try-callback/?error=state_not_provided`)
}

const client_id = (state == "production") ? process.env.NEXT_PUBLIC_TRY_IT_OUT_APP : process.env.NEXT_PUBLIC_TRY_IT_OUT_STAGING_APP
const client_secret = state == "production" ? process.env.SIGN_IN_SECRET_PROD : process.env.SIGN_IN_SECRET_STAGING
const client_id =
state == 'production' ? process.env.NEXT_PUBLIC_TRY_IT_OUT_APP : process.env.NEXT_PUBLIC_TRY_IT_OUT_STAGING_APP
const client_secret = state == 'production' ? process.env.SIGN_IN_SECRET_PROD : process.env.SIGN_IN_SECRET_STAGING

const tokenResponse = await fetch(`${process.env.NEXT_PUBLIC_SIGN_IN_WITH_WORLDCOIN_ENDPOINT}/token`, {
method: 'POST',
Expand All @@ -36,10 +36,10 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
})

if (!tokenResponse.ok) {
return redirect(res, `${process.env.NEXT_PUBLIC_APP_URL}/try-callback/?error=token_endpoint_error`)
return redirect(res, `${process.env.NEXT_PUBLIC_APP_URL}/world-id/try-callback/?error=token_endpoint_error`)
}

const access_token = (await tokenResponse.json()).access_token

return redirect(res, `${process.env.NEXT_PUBLIC_APP_URL}/try-callback/?token=${access_token}`)
}
return redirect(res, `${process.env.NEXT_PUBLIC_APP_URL}/world-id/try-callback/?token=${access_token}`)
}
2 changes: 1 addition & 1 deletion src/pages/world-id/reference/sign-in.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Redirect your users to this page to begin the sign-in flow.
<CodeGroup title="Request" tag="GET" label="/authorize">
```http
https://id.worldcoin.org/authorize?redirect_uri=https%3A%2F%2Fdocs.worldcoin.org%2Ftry-callback&response_type=code&scope=openid+profile+email&client_id=app_ce4cb73cb75fc3b73b71ffb4de178410
https://id.worldcoin.org/authorize?redirect_uri=https%3A%2F%2Fdocs.worldcoin.org%2Fworld-id%2Ftry-callback&response_type=code&scope=openid+profile+email&client_id=app_ce4cb73cb75fc3b73b71ffb4de178410
```
</CodeGroup>
Expand Down

0 comments on commit 4b03617

Please sign in to comment.