-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For authenticating the vscode extension using a URI scheme.
- Loading branch information
Showing
4 changed files
with
70 additions
and
1 deletion.
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,53 @@ | ||
import { Text, Button, Stack } from "@mantine/core"; | ||
import initTranslations from "../../i18n"; | ||
import { cookies } from "next/headers"; | ||
import { getMe } from "../../../api/usersApi"; | ||
import { redirect } from "next/navigation"; | ||
import Image from "next/image"; | ||
import Link from "next/link"; | ||
|
||
export default async function AuthorizePage({ | ||
params: { locale }, | ||
searchParams: { editor }, | ||
}: { | ||
params: { locale: string }; | ||
searchParams: { editor?: string }; | ||
}) { | ||
const { t } = await initTranslations(locale, ["common"]); | ||
|
||
const loginUrl = | ||
editor == "vscode" | ||
? `/login?redirect=${encodeURIComponent("/authorize?editor=vscode")}` | ||
: "/login"; | ||
|
||
const token = cookies().get("token")?.value; | ||
if (!token) { | ||
redirect(loginUrl); | ||
} | ||
|
||
const me = await getMe(); | ||
if (!me || "error" in me) { | ||
redirect(loginUrl); | ||
} | ||
|
||
const { username } = me; | ||
|
||
return ( | ||
<Stack align="center" gap="xl"> | ||
<Image | ||
src="/images/vscode.svg" | ||
alt="Visual Studio Code" | ||
width={40} | ||
height={40} | ||
/> | ||
<Text>{t("authorize.body")}</Text> | ||
<a href={`vscode://testausserveri-ry.testaustime/authorize?${token}`}> | ||
<Button>{t("authorize.continue", { username })}</Button> | ||
</a> | ||
<Text c="dark.2"> | ||
{t("authorize.notWorking.text")} | ||
<Link href="profile">{t("authorize.notWorking.link")}</Link> | ||
</Text> | ||
</Stack> | ||
); | ||
} |
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