forked from tryabby/abby
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): add auto login flow (tryabby#57)
* feat(cli): add auto login flow * feat(web): improve generate-token page * fix(cli): remove console.log * feat(cli): add init function * fix build and add cli docs
- Loading branch information
Showing
11 changed files
with
269 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { useQuery } from "@tanstack/react-query"; | ||
import { Layout } from "components/Layout"; | ||
import { GetServerSideProps, InferGetServerSidePropsType } from "next"; | ||
import { createContext } from "server/trpc/context"; | ||
import { appRouter } from "server/trpc/router/_app"; | ||
import { NextPageWithLayout } from "../_app"; | ||
import Logo from "components/Logo"; | ||
import { match } from "ts-pattern"; | ||
|
||
const GenerateTokenPage: NextPageWithLayout< | ||
InferGetServerSidePropsType<typeof getServerSideProps> | ||
> = ({ token, callbackUrl }) => { | ||
const { status } = useQuery(["generate-token"], () => { | ||
const url = new URL(callbackUrl as string); | ||
url.searchParams.set("token", token); | ||
return fetch(url); | ||
}); | ||
|
||
return ( | ||
<main className="absolute left-1/2 top-1/2 h-[400px] w-[300px] -translate-x-1/2 -translate-y-1/2 rounded-xl border border-gray-200 p-8 text-center"> | ||
<div className="flex h-full w-full flex-col items-center justify-between py-16"> | ||
<Logo /> | ||
<div> | ||
{match(status) | ||
.with("loading", () => <h1>Loading...</h1>) | ||
.with("error", () => <h1>Something went wrong!</h1>) | ||
.with("success", () => <h1>You can safely close this tab now!</h1>) | ||
.exhaustive()} | ||
</div> | ||
</div> | ||
</main> | ||
); | ||
}; | ||
|
||
GenerateTokenPage.getLayout = (page) => <Layout hideSidebar>{page}</Layout>; | ||
|
||
export const getServerSideProps = (async (ctx) => { | ||
const trpc = appRouter.createCaller(await createContext(ctx as any)); | ||
|
||
const token = await trpc.apikey.createApiKey({ | ||
name: "CLI Token", | ||
}); | ||
|
||
if (typeof ctx.query.callbackUrl != "string") { | ||
throw new Error("Missing callbackUrl"); | ||
} | ||
|
||
return { | ||
props: { | ||
token, | ||
callbackUrl: ctx.query.callbackUrl, | ||
}, | ||
}; | ||
}) satisfies GetServerSideProps; | ||
|
||
export default GenerateTokenPage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
# @tryabby/cli | ||
|
||
## 0.3.0 | ||
|
||
### Minor Changes | ||
|
||
- add auto login flow | ||
|
||
## 0.1.0 | ||
|
||
### Minor Changes | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { AbbyConfigFile } from "@tryabby/core"; | ||
import fs from "fs/promises"; | ||
import * as prettier from "prettier"; | ||
|
||
export async function initAbbyConfig({ path }: { path: string }) { | ||
const config: AbbyConfigFile = { | ||
projectId: "<YOUR_PROJECT_ID>", | ||
currentEnvironment: "<YOUR_ENVIRONMENT>", | ||
environments: [], | ||
}; | ||
|
||
const fileContent = ` | ||
import { defineConfig } from '@tryabby/core'; | ||
export default defineConfig(${JSON.stringify(config, null, 2)}); | ||
`; | ||
|
||
await fs.writeFile(path, await prettier.format(fileContent, { parser: "typescript" })); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.