diff --git a/public/locales/en/common.json b/public/locales/en/common.json index 22f7c2d0..a3cc44a9 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -298,5 +298,13 @@ "button": "Search" } } + }, + "authorize": { + "body": "You are logging in to the official Visual Studio Code extension.", + "continue": "Continue as {{username}}", + "notWorking": { + "text": "Not working?", + "link": "Copy authentication token on settings page." + } } } diff --git a/public/locales/fi/common.json b/public/locales/fi/common.json index 57960e0e..1a28119c 100644 --- a/public/locales/fi/common.json +++ b/public/locales/fi/common.json @@ -298,5 +298,13 @@ "button": "Etsi" } } + }, + "authorize": { + "body": "Olet kirjautumassa sisään viralliseen Visual Studio Code -lisäosaan.", + "continue": "Jatka käyttäjänä {{username}}", + "notWorking": { + "text": "Eikö toimi?", + "link": "Kopioi tunnistautumistunnus asetukset-sivulla." + } } } diff --git a/src/app/[locale]/authorize/page.tsx b/src/app/[locale]/authorize/page.tsx new file mode 100644 index 00000000..b12adf9a --- /dev/null +++ b/src/app/[locale]/authorize/page.tsx @@ -0,0 +1,56 @@ +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 ( + + Visual Studio Code + {t("authorize.body")} + + + {t("authorize.notWorking.text")}  + {t("authorize.notWorking.link")} + + + ); +} diff --git a/src/components/LoginForm/actions.ts b/src/components/LoginForm/actions.ts index a5e31f23..80219b96 100644 --- a/src/components/LoginForm/actions.ts +++ b/src/components/LoginForm/actions.ts @@ -17,7 +17,12 @@ export interface SecureAccessTokenResponse { token: string; } -const allowedRedirects = ["/profile", "/friends", "/leaderboards"]; +const allowedRedirects = [ + "/profile", + "/friends", + "/leaderboards", + "/authorize?editor=vscode", +]; export const logIn = async ( username: string,