diff --git a/.gitignore b/.gitignore index 8bea82447..6f3962009 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ node-compile-cache/ .eslintcache .env.local .env.*.local +scratch/ npm-debug.log* yarn-debug.log* diff --git a/apps/backend/src/app/api/latest/auth/cli/complete/route.tsx b/apps/backend/src/app/api/latest/auth/cli/complete/route.tsx index cf6a01c61..644bcbd87 100644 --- a/apps/backend/src/app/api/latest/auth/cli/complete/route.tsx +++ b/apps/backend/src/app/api/latest/auth/cli/complete/route.tsx @@ -25,9 +25,8 @@ export const POST = createSmartRouteHandler({ }), async handler({ auth: { tenancy }, body: { login_code, refresh_token } }) { // Find the CLI auth attempt - const cliAuth = await prismaClient.cliAuthAttempt.findFirst({ + const cliAuth = await prismaClient.cliAuthAttempt.findUnique({ where: { - tenancyId: tenancy.id, loginCode: login_code, refreshToken: null, expiresAt: { @@ -40,6 +39,10 @@ export const POST = createSmartRouteHandler({ throw new StatusError(400, "Invalid login code or the code has expired"); } + if (cliAuth.tenancyId !== tenancy.id) { + throw new StatusError(400, "Project ID mismatch; please ensure that you are using the correct app url."); + } + // Update with refresh token await prismaClient.cliAuthAttempt.update({ where: { diff --git a/apps/dashboard/public/stack_auth_cli_template.py b/docs/examples/stack_auth_cli_template.py similarity index 100% rename from apps/dashboard/public/stack_auth_cli_template.py rename to docs/examples/stack_auth_cli_template.py diff --git a/docs/fern/docs/pages-template/others/cli-authentication.mdx b/docs/fern/docs/pages-template/others/cli-authentication.mdx index b862faa22..1be9b0f88 100644 --- a/docs/fern/docs/pages-template/others/cli-authentication.mdx +++ b/docs/fern/docs/pages-template/others/cli-authentication.mdx @@ -5,7 +5,7 @@ description: How to authenticate a command line application using Stack Auth If you're building a command line application that runs in a terminal, you can use Stack Auth to let your users log in to their accounts. -To do so, we provide a Python template that you can use as a starting point. [Download it here](https://app.stack-auth.com/stack_auth_cli_template.py) and copy it into your project, for example: +To do so, we provide a Python template that you can use as a starting point. [Download it here](https://github.com/stack-auth/stack-auth/docs/examples/stack_auth_cli_template.py) and copy it into your project, for example: ```py └─ my-python-app