From a4b687d1f7764de5dea576598a53c650adb3b6fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Dere=C5=BEi=C4=87?= Date: Thu, 7 Mar 2024 13:19:19 +0100 Subject: [PATCH] implemented webview detection & warning --- app/[locale]/login/page.tsx | 39 +++++++++++++++++++++++++++++++------ messages/en.json | 1 + messages/hr.json | 7 ++++--- 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/app/[locale]/login/page.tsx b/app/[locale]/login/page.tsx index 8c8b87e..0a3385d 100644 --- a/app/[locale]/login/page.tsx +++ b/app/[locale]/login/page.tsx @@ -1,10 +1,13 @@ -import { FC } from 'react'; +import { FC, ReactNode } from 'react'; import { Main } from '@/app/ui/Main'; import { authConfig } from "@/app/lib/auth"; import { SignInButton } from '@/app/ui/SignInButton'; import Image from 'next/image'; import { getTranslations } from "next-intl/server"; +import isWebview from "is-ua-webview"; +import { headers } from 'next/headers' +import { ExclamationTriangleIcon } from "@heroicons/react/24/outline"; type Provider = { id: string; @@ -37,6 +40,12 @@ const Page:FC = async () => { const providers = await getProviders(); const t = await getTranslations("login-page"); + // get userAgent from NextJS + + const headersList = headers(); + const userAgent = headersList.get("user-agent") as string; + + const insideWebeview = isWebview(userAgent); return (
@@ -47,14 +56,32 @@ const Page:FC = async () => {

{t("main-card.text-1")}

{t("main-card.text-2")}

- { - Object.values(providers).map((provider) => ( -
- + // Google will refuse OAuth signin if it's inside a webview (i.e. Facebook) + insideWebeview && +
+
+ +
+
+ { + t.rich("main-card.in-app-browser-warning", { + br: () =>
, + strong: (chunks:ReactNode) => {chunks}, + hint: (chunks:ReactNode) => {chunks} + }) + }
- )) +
} + + { + Object.values(providers).map((provider) => ( +
+ +
+ )) + }