Skip to content

Commit

Permalink
try default kratos paths file
Browse files Browse the repository at this point in the history
  • Loading branch information
elbotho committed Apr 23, 2024
1 parent 2830e2f commit 5f40b03
Showing 1 changed file with 5 additions and 44 deletions.
49 changes: 5 additions & 44 deletions apps/web/src/pages/api/.ory/[...paths].ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { createApiHandler, config } from '@ory/integrations/next-edge'
import { NextApiRequest, NextApiResponse } from 'next/types'

export { config }

Expand All @@ -9,11 +8,6 @@ const COOKIE_DOMAINS = {
local: 'localhost',
}

const API_KRATOS_WEBHOOK_URL =
process.env.NEXT_PUBLIC_ENV === 'production'
? 'https://api.serlo.org/kratos/register'
: 'https://api.serlo-staging.dev/kratos/register'

export const COOKIE_DOMAIN =
process.env.NEXT_PUBLIC_ENV === 'production'
? COOKIE_DOMAINS['production']
Expand All @@ -33,41 +27,8 @@ const KRATOS_HOST =
process.env.NEXT_PUBLIC_ENV ? process.env.NEXT_PUBLIC_ENV : 'staging'
]

export default async function customCreateApiHandler(
req: NextApiRequest,
res: NextApiResponse<string>
): Promise<void> {
// injecting a function here to trigger an api call because
// unfortunately the kratos webhook ist not reliable atm.
// this is not used for the SSO flow (that still uses the kratos webhook)
if (
req.method === 'GET' &&
req.url?.startsWith('/api/.ory/self-service/verification') &&
process.env.API_KRATOS_SECRET
) {
console.log('afterRegisterApiCall: trying to call API')

void fetch(API_KRATOS_WEBHOOK_URL, {
method: 'POST',
headers: {
'x-kratos-key': process.env.API_KRATOS_SECRET,
'Content-Type': 'application/json',
},
})
.then(async (result) => {
const text = await result.text()
console.log(result.status)
console.error(text)
// if (result.status !== 200) {
// }
})
.catch((e) => console.error(e))
}

// continue with default kratos handler
return createApiHandler({
apiBaseUrlOverride: KRATOS_HOST,
forceCookieSecure: true,
forceCookieDomain: COOKIE_DOMAIN,
})(req, res)
}
export default createApiHandler({
apiBaseUrlOverride: KRATOS_HOST,
forceCookieSecure: true,
forceCookieDomain: COOKIE_DOMAIN,
})

0 comments on commit 5f40b03

Please sign in to comment.