feat: add i18n

This commit is contained in:
Stavros
2025-03-19 19:36:48 +02:00
parent 3ccc831a1f
commit fd32e737a3
44 changed files with 633 additions and 60 deletions

View File

@@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"io/fs" "io/fs"
"net/http" "net/http"
"os"
"strings" "strings"
"time" "time"
"tinyauth/internal/assets" "tinyauth/internal/assets"
@@ -69,7 +70,18 @@ func (api *API) Init() {
router.Use(func(c *gin.Context) { router.Use(func(c *gin.Context) {
// If not an API request, serve the UI // If not an API request, serve the UI
if !strings.HasPrefix(c.Request.URL.Path, "/api") { if !strings.HasPrefix(c.Request.URL.Path, "/api") {
// Check if the file exists
_, err := fs.Stat(dist, strings.TrimPrefix(c.Request.URL.Path, "/"))
// If the file doesn't exist, serve the index.html
if os.IsNotExist(err) {
c.Request.URL.Path = "/"
}
// Serve the file
fileServer.ServeHTTP(c.Writer, c.Request) fileServer.ServeHTTP(c.Writer, c.Request)
// Stop further processing
c.Abort() c.Abort()
} }
}) })

Binary file not shown.

View File

@@ -16,8 +16,12 @@
"@mantine/notifications": "^7.16.0", "@mantine/notifications": "^7.16.0",
"@tanstack/react-query": "4", "@tanstack/react-query": "4",
"axios": "^1.7.9", "axios": "^1.7.9",
"i18next": "^24.2.3",
"i18next-browser-languagedetector": "^8.0.4",
"i18next-resources-to-backend": "^1.2.1",
"react": "^18.3.1", "react": "^18.3.1",
"react-dom": "^18.3.1", "react-dom": "^18.3.1",
"react-i18next": "^15.4.1",
"react-router": "^7.1.3", "react-router": "^7.1.3",
"zod": "^3.24.1" "zod": "^3.24.1"
}, },

View File

@@ -1,6 +1,7 @@
import { TextInput, PasswordInput, Button } from "@mantine/core"; import { TextInput, PasswordInput, Button } from "@mantine/core";
import { useForm, zodResolver } from "@mantine/form"; import { useForm, zodResolver } from "@mantine/form";
import { LoginFormValues, loginSchema } from "../../schemas/login-schema"; import { LoginFormValues, loginSchema } from "../../schemas/login-schema";
import { useTranslation } from "react-i18next";
interface LoginFormProps { interface LoginFormProps {
isLoading: boolean; isLoading: boolean;
@@ -9,6 +10,7 @@ interface LoginFormProps {
export const LoginForm = (props: LoginFormProps) => { export const LoginForm = (props: LoginFormProps) => {
const { isLoading, onSubmit } = props; const { isLoading, onSubmit } = props;
const { t } = useTranslation();
const form = useForm({ const form = useForm({
mode: "uncontrolled", mode: "uncontrolled",
@@ -22,7 +24,7 @@ export const LoginForm = (props: LoginFormProps) => {
return ( return (
<form onSubmit={form.onSubmit(onSubmit)}> <form onSubmit={form.onSubmit(onSubmit)}>
<TextInput <TextInput
label="Username" label={t("loginUsername")}
placeholder="user@example.com" placeholder="user@example.com"
required required
disabled={isLoading} disabled={isLoading}
@@ -30,7 +32,7 @@ export const LoginForm = (props: LoginFormProps) => {
{...form.getInputProps("username")} {...form.getInputProps("username")}
/> />
<PasswordInput <PasswordInput
label="Password" label={t("loginPassword")}
placeholder="password" placeholder="password"
required required
mt="md" mt="md"
@@ -39,7 +41,7 @@ export const LoginForm = (props: LoginFormProps) => {
{...form.getInputProps("password")} {...form.getInputProps("password")}
/> />
<Button fullWidth mt="xl" type="submit" loading={isLoading}> <Button fullWidth mt="xl" type="submit" loading={isLoading}>
Login {t("loginSubmit")}
</Button> </Button>
</form> </form>
); );

20
site/src/lib/i18n/i18n.ts Normal file
View File

@@ -0,0 +1,20 @@
import i18n from 'i18next';
import { initReactI18next } from 'react-i18next';
import LanguageDetector from 'i18next-browser-languagedetector';
import resourcesToBackend from 'i18next-resources-to-backend';
i18n
.use(LanguageDetector)
.use(initReactI18next)
.use(resourcesToBackend((language: string) => import(`./locales/${language}.json`)))
.init({
fallbackLng: 'en',
debug: import.meta.env.MODE === 'development',
interpolation: {
escapeValue: false,
}
});
export default i18n;

View File

@@ -0,0 +1,15 @@
{
"loginTitle": "Welcome back, login with",
"loginDivider": "Or continue with password",
"loginUsername": "Username",
"loginPassword": "Password",
"loginSubmit": "Login",
"loginFailTitle": "Failed to login",
"loginFailSubtitle": "Please check your username and password",
"loginSuccessTitle": "Logged in",
"loginSuccessSubtitle": "Welcome back!",
"loginOauthFailTitle": "Internal error",
"loginOauthFailSubtitle": "Failed to get OAuth URL",
"loginOauthSuccessTitle": "Redirecting",
"loginOauthSuccessSubtitle": "Redirecting to your OAuth provider"
}

View File

@@ -0,0 +1,15 @@
{
"loginTitle": "Welcome back, login with",
"loginDivider": "Or continue with password",
"loginUsername": "Username",
"loginPassword": "Password",
"loginSubmit": "Login",
"loginFailTitle": "Failed to login",
"loginFailSubtitle": "Please check your username and password",
"loginSuccessTitle": "Logged in",
"loginSuccessSubtitle": "Welcome back!",
"loginOauthFailTitle": "Internal error",
"loginOauthFailSubtitle": "Failed to get OAuth URL",
"loginOauthSuccessTitle": "Redirecting",
"loginOauthSuccessSubtitle": "Redirecting to your OAuth provider"
}

View File

@@ -0,0 +1,15 @@
{
"loginTitle": "Welcome back, login with",
"loginDivider": "Or continue with password",
"loginUsername": "Username",
"loginPassword": "Password",
"loginSubmit": "Login",
"loginFailTitle": "Failed to login",
"loginFailSubtitle": "Please check your username and password",
"loginSuccessTitle": "Logged in",
"loginSuccessSubtitle": "Welcome back!",
"loginOauthFailTitle": "Internal error",
"loginOauthFailSubtitle": "Failed to get OAuth URL",
"loginOauthSuccessTitle": "Redirecting",
"loginOauthSuccessSubtitle": "Redirecting to your OAuth provider"
}

View File

@@ -0,0 +1,15 @@
{
"loginTitle": "Welcome back, login with",
"loginDivider": "Or continue with password",
"loginUsername": "Username",
"loginPassword": "Password",
"loginSubmit": "Login",
"loginFailTitle": "Failed to login",
"loginFailSubtitle": "Please check your username and password",
"loginSuccessTitle": "Logged in",
"loginSuccessSubtitle": "Welcome back!",
"loginOauthFailTitle": "Internal error",
"loginOauthFailSubtitle": "Failed to get OAuth URL",
"loginOauthSuccessTitle": "Redirecting",
"loginOauthSuccessSubtitle": "Redirecting to your OAuth provider"
}

View File

@@ -0,0 +1,15 @@
{
"loginTitle": "Welcome back, login with",
"loginDivider": "Or continue with password",
"loginUsername": "Username",
"loginPassword": "Password",
"loginSubmit": "Login",
"loginFailTitle": "Failed to login",
"loginFailSubtitle": "Please check your username and password",
"loginSuccessTitle": "Logged in",
"loginSuccessSubtitle": "Welcome back!",
"loginOauthFailTitle": "Internal error",
"loginOauthFailSubtitle": "Failed to get OAuth URL",
"loginOauthSuccessTitle": "Redirecting",
"loginOauthSuccessSubtitle": "Redirecting to your OAuth provider"
}

View File

@@ -0,0 +1,15 @@
{
"loginTitle": "Welcome back, login with",
"loginDivider": "Or continue with password",
"loginUsername": "Username",
"loginPassword": "Password",
"loginSubmit": "Login",
"loginFailTitle": "Failed to login",
"loginFailSubtitle": "Please check your username and password",
"loginSuccessTitle": "Logged in",
"loginSuccessSubtitle": "Welcome back!",
"loginOauthFailTitle": "Internal error",
"loginOauthFailSubtitle": "Failed to get OAuth URL",
"loginOauthSuccessTitle": "Redirecting",
"loginOauthSuccessSubtitle": "Redirecting to your OAuth provider"
}

View File

@@ -0,0 +1,15 @@
{
"loginTitle": "Welcome back, login with",
"loginDivider": "Or continue with password",
"loginUsername": "Username",
"loginPassword": "Password",
"loginSubmit": "Login",
"loginFailTitle": "Failed to login",
"loginFailSubtitle": "Please check your username and password",
"loginSuccessTitle": "Logged in",
"loginSuccessSubtitle": "Welcome back!",
"loginOauthFailTitle": "Internal error",
"loginOauthFailSubtitle": "Failed to get OAuth URL",
"loginOauthSuccessTitle": "Redirecting",
"loginOauthSuccessSubtitle": "Redirecting to your OAuth provider"
}

View File

@@ -0,0 +1,15 @@
{
"loginTitle": "Welcome back, login with",
"loginDivider": "Or continue with password",
"loginUsername": "Username",
"loginPassword": "Password",
"loginSubmit": "Login",
"loginFailTitle": "Failed to login",
"loginFailSubtitle": "Please check your username and password",
"loginSuccessTitle": "Logged in",
"loginSuccessSubtitle": "Welcome back!",
"loginOauthFailTitle": "Internal error",
"loginOauthFailSubtitle": "Failed to get OAuth URL",
"loginOauthSuccessTitle": "Redirecting",
"loginOauthSuccessSubtitle": "Redirecting to your OAuth provider"
}

View File

@@ -0,0 +1,45 @@
{
"loginTitle": "Welcome back, login with",
"loginDivider": "Or continue with password",
"loginUsername": "Username",
"loginPassword": "Password",
"loginSubmit": "Login",
"loginFailTitle": "Failed to login",
"loginFailSubtitle": "Please check your username and password",
"loginSuccessTitle": "Logged in",
"loginSuccessSubtitle": "Welcome back!",
"loginOauthFailTitle": "Internal error",
"loginOauthFailSubtitle": "Failed to get OAuth URL",
"loginOauthSuccessTitle": "Redirecting",
"loginOauthSuccessSubtitle": "Redirecting to your OAuth provider",
"continueRedirectingTitle": "Redirecting...",
"continueRedirectingSubtitle": "You should be redirected to the app soon",
"continueInvalidRedirectTitle": "Invalid redirect",
"continueInvalidRedirectSubtitle": "The redirect URL is invalid",
"continueInsecureRedirectTitle": "Insecure redirect",
"continueInsecureRedirectSubtitle": "You are trying to redirect from <Code>https</Code> to <Code>http</Code>, are you sure you want to continue?",
"continueTitle": "Continue",
"continueSubtitle": "Click the button to continue to your app.",
"internalErrorTitle": "Internal Server Error",
"internalErrorSubtitle": "An error occured on the server and it currently cannot serve your request.",
"internalErrorButton": "Try again",
"logoutFailTitle": "Failed to logout",
"logoutFailSubtitle": "Please try again",
"logoutSuccessTitle": "Logged out",
"logoutSuccessSubtitle": "You have been logged out",
"logoutTitle": "Logout",
"logoutUsernameSubtitle": "You are currently logged in as <Code>{{username}}</Code>, click the button below to logout.",
"logoutOauthSubtitle": "You are currently logged in as <Code>{{username}}</Code> using the {{provider}} OAuth provider, click the button below to logout.",
"notFoundTitle": "Page not found",
"notFoundSubtitle": "The page you are looking for does not exist.",
"notFoundButton": "Go home",
"totpFailTitle": "Failed to verify code",
"totpFailSubtitle": "Please check your code and try again",
"totpSuccessTitle": "Verified",
"totpSuccessSubtitle": "Redirecting to your app",
"totpTitle": "Enter your TOTP code",
"unauthorizedTitle": "Unauthorized",
"unauthorizedResourceSubtitle": "The user with username {{username}} is not authorized to access the resource <Code>{{resource}}</Code>.",
"unaothorizedLoginSubtitle": "The user with username {{username}} is not authorized to login.",
"unauthorizedButton": "Try again"
}

View File

@@ -0,0 +1,15 @@
{
"loginTitle": "Welcome back, login with",
"loginDivider": "Or continue with password",
"loginUsername": "Username",
"loginPassword": "Password",
"loginSubmit": "Login",
"loginFailTitle": "Failed to login",
"loginFailSubtitle": "Please check your username and password",
"loginSuccessTitle": "Logged in",
"loginSuccessSubtitle": "Welcome back!",
"loginOauthFailTitle": "Internal error",
"loginOauthFailSubtitle": "Failed to get OAuth URL",
"loginOauthSuccessTitle": "Redirecting",
"loginOauthSuccessSubtitle": "Redirecting to your OAuth provider"
}

View File

@@ -0,0 +1,15 @@
{
"loginTitle": "Welcome back, login with",
"loginDivider": "Or continue with password",
"loginUsername": "Username",
"loginPassword": "Password",
"loginSubmit": "Login",
"loginFailTitle": "Failed to login",
"loginFailSubtitle": "Please check your username and password",
"loginSuccessTitle": "Logged in",
"loginSuccessSubtitle": "Welcome back!",
"loginOauthFailTitle": "Internal error",
"loginOauthFailSubtitle": "Failed to get OAuth URL",
"loginOauthSuccessTitle": "Redirecting",
"loginOauthSuccessSubtitle": "Redirecting to your OAuth provider"
}

View File

@@ -0,0 +1,15 @@
{
"loginTitle": "Welcome back, login with",
"loginDivider": "Or continue with password",
"loginUsername": "Username",
"loginPassword": "Password",
"loginSubmit": "Login",
"loginFailTitle": "Failed to login",
"loginFailSubtitle": "Please check your username and password",
"loginSuccessTitle": "Logged in",
"loginSuccessSubtitle": "Welcome back!",
"loginOauthFailTitle": "Internal error",
"loginOauthFailSubtitle": "Failed to get OAuth URL",
"loginOauthSuccessTitle": "Redirecting",
"loginOauthSuccessSubtitle": "Redirecting to your OAuth provider"
}

View File

@@ -0,0 +1,15 @@
{
"loginTitle": "Welcome back, login with",
"loginDivider": "Or continue with password",
"loginUsername": "Username",
"loginPassword": "Password",
"loginSubmit": "Login",
"loginFailTitle": "Failed to login",
"loginFailSubtitle": "Please check your username and password",
"loginSuccessTitle": "Logged in",
"loginSuccessSubtitle": "Welcome back!",
"loginOauthFailTitle": "Internal error",
"loginOauthFailSubtitle": "Failed to get OAuth URL",
"loginOauthSuccessTitle": "Redirecting",
"loginOauthSuccessSubtitle": "Redirecting to your OAuth provider"
}

View File

@@ -0,0 +1,15 @@
{
"loginTitle": "Welcome back, login with",
"loginDivider": "Or continue with password",
"loginUsername": "Username",
"loginPassword": "Password",
"loginSubmit": "Login",
"loginFailTitle": "Failed to login",
"loginFailSubtitle": "Please check your username and password",
"loginSuccessTitle": "Logged in",
"loginSuccessSubtitle": "Welcome back!",
"loginOauthFailTitle": "Internal error",
"loginOauthFailSubtitle": "Failed to get OAuth URL",
"loginOauthSuccessTitle": "Redirecting",
"loginOauthSuccessSubtitle": "Redirecting to your OAuth provider"
}

View File

@@ -0,0 +1,15 @@
{
"loginTitle": "Welcome back, login with",
"loginDivider": "Or continue with password",
"loginUsername": "Username",
"loginPassword": "Password",
"loginSubmit": "Login",
"loginFailTitle": "Failed to login",
"loginFailSubtitle": "Please check your username and password",
"loginSuccessTitle": "Logged in",
"loginSuccessSubtitle": "Welcome back!",
"loginOauthFailTitle": "Internal error",
"loginOauthFailSubtitle": "Failed to get OAuth URL",
"loginOauthSuccessTitle": "Redirecting",
"loginOauthSuccessSubtitle": "Redirecting to your OAuth provider"
}

View File

@@ -0,0 +1,15 @@
{
"loginTitle": "Welcome back, login with",
"loginDivider": "Or continue with password",
"loginUsername": "Username",
"loginPassword": "Password",
"loginSubmit": "Login",
"loginFailTitle": "Failed to login",
"loginFailSubtitle": "Please check your username and password",
"loginSuccessTitle": "Logged in",
"loginSuccessSubtitle": "Welcome back!",
"loginOauthFailTitle": "Internal error",
"loginOauthFailSubtitle": "Failed to get OAuth URL",
"loginOauthSuccessTitle": "Redirecting",
"loginOauthSuccessSubtitle": "Redirecting to your OAuth provider"
}

View File

@@ -0,0 +1,15 @@
{
"loginTitle": "Welcome back, login with",
"loginDivider": "Or continue with password",
"loginUsername": "Username",
"loginPassword": "Password",
"loginSubmit": "Login",
"loginFailTitle": "Failed to login",
"loginFailSubtitle": "Please check your username and password",
"loginSuccessTitle": "Logged in",
"loginSuccessSubtitle": "Welcome back!",
"loginOauthFailTitle": "Internal error",
"loginOauthFailSubtitle": "Failed to get OAuth URL",
"loginOauthSuccessTitle": "Redirecting",
"loginOauthSuccessSubtitle": "Redirecting to your OAuth provider"
}

View File

@@ -0,0 +1,15 @@
{
"loginTitle": "Welcome back, login with",
"loginDivider": "Or continue with password",
"loginUsername": "Username",
"loginPassword": "Password",
"loginSubmit": "Login",
"loginFailTitle": "Failed to login",
"loginFailSubtitle": "Please check your username and password",
"loginSuccessTitle": "Logged in",
"loginSuccessSubtitle": "Welcome back!",
"loginOauthFailTitle": "Internal error",
"loginOauthFailSubtitle": "Failed to get OAuth URL",
"loginOauthSuccessTitle": "Redirecting",
"loginOauthSuccessSubtitle": "Redirecting to your OAuth provider"
}

View File

@@ -0,0 +1,15 @@
{
"loginTitle": "Welcome back, login with",
"loginDivider": "Or continue with password",
"loginUsername": "Username",
"loginPassword": "Password",
"loginSubmit": "Login",
"loginFailTitle": "Failed to login",
"loginFailSubtitle": "Please check your username and password",
"loginSuccessTitle": "Logged in",
"loginSuccessSubtitle": "Welcome back!",
"loginOauthFailTitle": "Internal error",
"loginOauthFailSubtitle": "Failed to get OAuth URL",
"loginOauthSuccessTitle": "Redirecting",
"loginOauthSuccessSubtitle": "Redirecting to your OAuth provider"
}

View File

@@ -0,0 +1,15 @@
{
"loginTitle": "Welcome back, login with",
"loginDivider": "Or continue with password",
"loginUsername": "Username",
"loginPassword": "Password",
"loginSubmit": "Login",
"loginFailTitle": "Failed to login",
"loginFailSubtitle": "Please check your username and password",
"loginSuccessTitle": "Logged in",
"loginSuccessSubtitle": "Welcome back!",
"loginOauthFailTitle": "Internal error",
"loginOauthFailSubtitle": "Failed to get OAuth URL",
"loginOauthSuccessTitle": "Redirecting",
"loginOauthSuccessSubtitle": "Redirecting to your OAuth provider"
}

View File

@@ -0,0 +1,15 @@
{
"loginTitle": "Welcome back, login with",
"loginDivider": "Or continue with password",
"loginUsername": "Username",
"loginPassword": "Password",
"loginSubmit": "Login",
"loginFailTitle": "Failed to login",
"loginFailSubtitle": "Please check your username and password",
"loginSuccessTitle": "Logged in",
"loginSuccessSubtitle": "Welcome back!",
"loginOauthFailTitle": "Internal error",
"loginOauthFailSubtitle": "Failed to get OAuth URL",
"loginOauthSuccessTitle": "Redirecting",
"loginOauthSuccessSubtitle": "Redirecting to your OAuth provider"
}

View File

@@ -0,0 +1,15 @@
{
"loginTitle": "Welcome back, login with",
"loginDivider": "Or continue with password",
"loginUsername": "Username",
"loginPassword": "Password",
"loginSubmit": "Login",
"loginFailTitle": "Failed to login",
"loginFailSubtitle": "Please check your username and password",
"loginSuccessTitle": "Logged in",
"loginSuccessSubtitle": "Welcome back!",
"loginOauthFailTitle": "Internal error",
"loginOauthFailSubtitle": "Failed to get OAuth URL",
"loginOauthSuccessTitle": "Redirecting",
"loginOauthSuccessSubtitle": "Redirecting to your OAuth provider"
}

View File

@@ -0,0 +1,15 @@
{
"loginTitle": "Welcome back, login with",
"loginDivider": "Or continue with password",
"loginUsername": "Username",
"loginPassword": "Password",
"loginSubmit": "Login",
"loginFailTitle": "Failed to login",
"loginFailSubtitle": "Please check your username and password",
"loginSuccessTitle": "Logged in",
"loginSuccessSubtitle": "Welcome back!",
"loginOauthFailTitle": "Internal error",
"loginOauthFailSubtitle": "Failed to get OAuth URL",
"loginOauthSuccessTitle": "Redirecting",
"loginOauthSuccessSubtitle": "Redirecting to your OAuth provider"
}

View File

@@ -0,0 +1,15 @@
{
"loginTitle": "Welcome back, login with",
"loginDivider": "Or continue with password",
"loginUsername": "Username",
"loginPassword": "Password",
"loginSubmit": "Login",
"loginFailTitle": "Failed to login",
"loginFailSubtitle": "Please check your username and password",
"loginSuccessTitle": "Logged in",
"loginSuccessSubtitle": "Welcome back!",
"loginOauthFailTitle": "Internal error",
"loginOauthFailSubtitle": "Failed to get OAuth URL",
"loginOauthSuccessTitle": "Redirecting",
"loginOauthSuccessSubtitle": "Redirecting to your OAuth provider"
}

View File

@@ -0,0 +1,15 @@
{
"loginTitle": "Welcome back, login with",
"loginDivider": "Or continue with password",
"loginUsername": "Username",
"loginPassword": "Password",
"loginSubmit": "Login",
"loginFailTitle": "Failed to login",
"loginFailSubtitle": "Please check your username and password",
"loginSuccessTitle": "Logged in",
"loginSuccessSubtitle": "Welcome back!",
"loginOauthFailTitle": "Internal error",
"loginOauthFailSubtitle": "Failed to get OAuth URL",
"loginOauthSuccessTitle": "Redirecting",
"loginOauthSuccessSubtitle": "Redirecting to your OAuth provider"
}

View File

@@ -0,0 +1,15 @@
{
"loginTitle": "Welcome back, login with",
"loginDivider": "Or continue with password",
"loginUsername": "Username",
"loginPassword": "Password",
"loginSubmit": "Login",
"loginFailTitle": "Failed to login",
"loginFailSubtitle": "Please check your username and password",
"loginSuccessTitle": "Logged in",
"loginSuccessSubtitle": "Welcome back!",
"loginOauthFailTitle": "Internal error",
"loginOauthFailSubtitle": "Failed to get OAuth URL",
"loginOauthSuccessTitle": "Redirecting",
"loginOauthSuccessSubtitle": "Redirecting to your OAuth provider"
}

View File

@@ -0,0 +1,15 @@
{
"loginTitle": "Welcome back, login with",
"loginDivider": "Or continue with password",
"loginUsername": "Username",
"loginPassword": "Password",
"loginSubmit": "Login",
"loginFailTitle": "Failed to login",
"loginFailSubtitle": "Please check your username and password",
"loginSuccessTitle": "Logged in",
"loginSuccessSubtitle": "Welcome back!",
"loginOauthFailTitle": "Internal error",
"loginOauthFailSubtitle": "Failed to get OAuth URL",
"loginOauthSuccessTitle": "Redirecting",
"loginOauthSuccessSubtitle": "Redirecting to your OAuth provider"
}

View File

@@ -0,0 +1,15 @@
{
"loginTitle": "Welcome back, login with",
"loginDivider": "Or continue with password",
"loginUsername": "Username",
"loginPassword": "Password",
"loginSubmit": "Login",
"loginFailTitle": "Failed to login",
"loginFailSubtitle": "Please check your username and password",
"loginSuccessTitle": "Logged in",
"loginSuccessSubtitle": "Welcome back!",
"loginOauthFailTitle": "Internal error",
"loginOauthFailSubtitle": "Failed to get OAuth URL",
"loginOauthSuccessTitle": "Redirecting",
"loginOauthSuccessSubtitle": "Redirecting to your OAuth provider"
}

View File

@@ -0,0 +1,15 @@
{
"loginTitle": "Welcome back, login with",
"loginDivider": "Or continue with password",
"loginUsername": "Username",
"loginPassword": "Password",
"loginSubmit": "Login",
"loginFailTitle": "Failed to login",
"loginFailSubtitle": "Please check your username and password",
"loginSuccessTitle": "Logged in",
"loginSuccessSubtitle": "Welcome back!",
"loginOauthFailTitle": "Internal error",
"loginOauthFailSubtitle": "Failed to get OAuth URL",
"loginOauthSuccessTitle": "Redirecting",
"loginOauthSuccessSubtitle": "Redirecting to your OAuth provider"
}

View File

@@ -0,0 +1,15 @@
{
"loginTitle": "Welcome back, login with",
"loginDivider": "Or continue with password",
"loginUsername": "Username",
"loginPassword": "Password",
"loginSubmit": "Login",
"loginFailTitle": "Failed to login",
"loginFailSubtitle": "Please check your username and password",
"loginSuccessTitle": "Logged in",
"loginSuccessSubtitle": "Welcome back!",
"loginOauthFailTitle": "Internal error",
"loginOauthFailSubtitle": "Failed to get OAuth URL",
"loginOauthSuccessTitle": "Redirecting",
"loginOauthSuccessSubtitle": "Redirecting to your OAuth provider"
}

View File

@@ -0,0 +1,15 @@
{
"loginTitle": "Welcome back, login with",
"loginDivider": "Or continue with password",
"loginUsername": "Username",
"loginPassword": "Password",
"loginSubmit": "Login",
"loginFailTitle": "Failed to login",
"loginFailSubtitle": "Please check your username and password",
"loginSuccessTitle": "Logged in",
"loginSuccessSubtitle": "Welcome back!",
"loginOauthFailTitle": "Internal error",
"loginOauthFailSubtitle": "Failed to get OAuth URL",
"loginOauthSuccessTitle": "Redirecting",
"loginOauthSuccessSubtitle": "Redirecting to your OAuth provider"
}

View File

@@ -17,6 +17,7 @@ import { UnauthorizedPage } from "./pages/unauthorized-page.tsx";
import { InternalServerError } from "./pages/internal-server-error.tsx"; import { InternalServerError } from "./pages/internal-server-error.tsx";
import { TotpPage } from "./pages/totp-page.tsx"; import { TotpPage } from "./pages/totp-page.tsx";
import { AppContextProvider } from "./context/app-context.tsx"; import { AppContextProvider } from "./context/app-context.tsx";
import "./lib/i18n/i18n.ts";
const queryClient = new QueryClient({ const queryClient = new QueryClient({
defaultOptions: { defaultOptions: {

View File

@@ -6,6 +6,7 @@ import { Layout } from "../components/layouts/layout";
import { ReactNode } from "react"; import { ReactNode } from "react";
import { isQueryValid } from "../utils/utils"; import { isQueryValid } from "../utils/utils";
import { useAppContext } from "../context/app-context"; import { useAppContext } from "../context/app-context";
import { Trans, useTranslation } from "react-i18next";
export const ContinuePage = () => { export const ContinuePage = () => {
const queryString = window.location.search; const queryString = window.location.search;
@@ -14,6 +15,7 @@ export const ContinuePage = () => {
const { isLoggedIn } = useUserContext(); const { isLoggedIn } = useUserContext();
const { disableContinue } = useAppContext(); const { disableContinue } = useAppContext();
const { t } = useTranslation();
if (!isLoggedIn) { if (!isLoggedIn) {
return <Navigate to={`/login?redirect_uri=${redirectUri}`} />; return <Navigate to={`/login?redirect_uri=${redirectUri}`} />;
@@ -25,8 +27,8 @@ export const ContinuePage = () => {
const redirect = () => { const redirect = () => {
notifications.show({ notifications.show({
title: "Redirecting", title: t("continueRedirectingTitle"),
message: "You should be redirected to the app soon", message: t("continueRedirectingSubtitle"),
color: "blue", color: "blue",
}); });
setTimeout(() => { setTimeout(() => {
@@ -42,12 +44,9 @@ export const ContinuePage = () => {
return ( return (
<ContinuePageLayout> <ContinuePageLayout>
<Text size="xl" fw={700}> <Text size="xl" fw={700}>
Invalid Redirect {t("Invalid redirect")}
</Text>
<Text>
The redirect URL is invalid, please contact the app owner to fix the
issue.
</Text> </Text>
<Text>{t("The redirect URL is invalid")}</Text>
</ContinuePageLayout> </ContinuePageLayout>
); );
} }
@@ -57,9 +56,9 @@ export const ContinuePage = () => {
return ( return (
<ContinuePageLayout> <ContinuePageLayout>
<Text size="xl" fw={700}> <Text size="xl" fw={700}>
Redirecting {t("continueRedirectingTitle")}
</Text> </Text>
<Text>You should be redirected to your app soon.</Text> <Text>{t("continueRedirectingSubtitle")}</Text>
</ContinuePageLayout> </ContinuePageLayout>
); );
} }
@@ -68,14 +67,17 @@ export const ContinuePage = () => {
return ( return (
<ContinuePageLayout> <ContinuePageLayout>
<Text size="xl" fw={700}> <Text size="xl" fw={700}>
Insecure Redirect {t("continueInsecureRedirectTitle")}
</Text> </Text>
<Text> <Text>
Your are trying to redirect from <Code>https</Code> to{" "} <Trans
<Code>http</Code>, are you sure you want to continue? i18nKey="continueInsecureRedirectSubtitle"
t={t}
components={{ Code: <Code /> }}
/>
</Text> </Text>
<Button fullWidth mt="xl" color="yellow" onClick={redirect}> <Button fullWidth mt="xl" color="yellow" onClick={redirect}>
Continue {t("continueTitle")}
</Button> </Button>
</ContinuePageLayout> </ContinuePageLayout>
); );
@@ -84,11 +86,11 @@ export const ContinuePage = () => {
return ( return (
<ContinuePageLayout> <ContinuePageLayout>
<Text size="xl" fw={700}> <Text size="xl" fw={700}>
Continue {t("continueTitle")}
</Text> </Text>
<Text>Click the button to continue to your app.</Text> <Text>{t("continueSubtitle")}</Text>
<Button fullWidth mt="xl" onClick={redirect}> <Button fullWidth mt="xl" onClick={redirect}>
Continue {t("continueTitle")}
</Button> </Button>
</ContinuePageLayout> </ContinuePageLayout>
); );

View File

@@ -1,19 +1,18 @@
import { Button, Paper, Text } from "@mantine/core"; import { Button, Paper, Text } from "@mantine/core";
import { Layout } from "../components/layouts/layout"; import { Layout } from "../components/layouts/layout";
import { useTranslation } from "react-i18next";
export const InternalServerError = () => { export const InternalServerError = () => {
const { t } = useTranslation();
return ( return (
<Layout> <Layout>
<Paper shadow="md" p={30} mt={30} radius="md" withBorder> <Paper shadow="md" p={30} mt={30} radius="md" withBorder>
<Text size="xl" fw={700}> <Text size="xl" fw={700}>
Internal Server Error {t("internalErrorTitle")}
</Text>
<Text>
An error occured on the server and it currently cannot serve your
request.
</Text> </Text>
<Text>{t("internalErrorSubtitle")}</Text>
<Button fullWidth mt="xl" onClick={() => window.location.replace("/")}> <Button fullWidth mt="xl" onClick={() => window.location.replace("/")}>
Try again {t("internalErrorButton")}
</Button> </Button>
</Paper> </Paper>
</Layout> </Layout>

View File

@@ -10,6 +10,7 @@ import { LoginFormValues } from "../schemas/login-schema";
import { LoginForm } from "../components/auth/login-forn"; import { LoginForm } from "../components/auth/login-forn";
import { isQueryValid } from "../utils/utils"; import { isQueryValid } from "../utils/utils";
import { useAppContext } from "../context/app-context"; import { useAppContext } from "../context/app-context";
import { useTranslation } from "react-i18next";
export const LoginPage = () => { export const LoginPage = () => {
const queryString = window.location.search; const queryString = window.location.search;
@@ -18,6 +19,7 @@ export const LoginPage = () => {
const { isLoggedIn } = useUserContext(); const { isLoggedIn } = useUserContext();
const { configuredProviders, title, genericName } = useAppContext(); const { configuredProviders, title, genericName } = useAppContext();
const { t } = useTranslation();
const oauthProviders = configuredProviders.filter( const oauthProviders = configuredProviders.filter(
(value) => value !== "username", (value) => value !== "username",
@@ -33,8 +35,8 @@ export const LoginPage = () => {
}, },
onError: () => { onError: () => {
notifications.show({ notifications.show({
title: "Failed to login", title: t("loginFailTitle"),
message: "Check your username and password", message: t("loginFailSubtitle"),
color: "red", color: "red",
}); });
}, },
@@ -45,8 +47,8 @@ export const LoginPage = () => {
} }
notifications.show({ notifications.show({
title: "Logged in", title: t("loginSuccessTitle"),
message: "Welcome back!", message: t("loginSuccessSubtitle"),
color: "green", color: "green",
}); });
@@ -69,15 +71,15 @@ export const LoginPage = () => {
}, },
onError: () => { onError: () => {
notifications.show({ notifications.show({
title: "Internal error", title: t("loginOauthFailTitle"),
message: "Failed to get OAuth URL", message: t("loginOauthFailSubtitle"),
color: "red", color: "red",
}); });
}, },
onSuccess: (data) => { onSuccess: (data) => {
notifications.show({ notifications.show({
title: "Redirecting", title: t("loginOauthSuccessTitle"),
message: "Redirecting to your OAuth provider", message: t("loginOauthSuccessSubtitle"),
color: "blue", color: "blue",
}); });
setTimeout(() => { setTimeout(() => {
@@ -97,7 +99,7 @@ export const LoginPage = () => {
{oauthProviders.length > 0 && ( {oauthProviders.length > 0 && (
<> <>
<Text size="lg" fw={500} ta="center"> <Text size="lg" fw={500} ta="center">
Welcome back, login with {t("loginTitle")}
</Text> </Text>
<OAuthButtons <OAuthButtons
oauthProviders={oauthProviders} oauthProviders={oauthProviders}
@@ -107,7 +109,7 @@ export const LoginPage = () => {
/> />
{configuredProviders.includes("username") && ( {configuredProviders.includes("username") && (
<Divider <Divider
label="Or continue with password" label={t("loginDivider")}
labelPosition="center" labelPosition="center"
my="lg" my="lg"
/> />

View File

@@ -7,10 +7,12 @@ import { Navigate } from "react-router";
import { Layout } from "../components/layouts/layout"; import { Layout } from "../components/layouts/layout";
import { capitalize } from "../utils/utils"; import { capitalize } from "../utils/utils";
import { useAppContext } from "../context/app-context"; import { useAppContext } from "../context/app-context";
import { Trans, useTranslation } from "react-i18next";
export const LogoutPage = () => { export const LogoutPage = () => {
const { isLoggedIn, username, oauth, provider } = useUserContext(); const { isLoggedIn, username, oauth, provider } = useUserContext();
const { genericName } = useAppContext(); const { genericName } = useAppContext();
const { t } = useTranslation();
if (!isLoggedIn) { if (!isLoggedIn) {
return <Navigate to="/login" />; return <Navigate to="/login" />;
@@ -22,15 +24,15 @@ export const LogoutPage = () => {
}, },
onError: () => { onError: () => {
notifications.show({ notifications.show({
title: "Failed to logout", title: t("logoutFailTitle"),
message: "Please try again", message: t("logoutFailSubtitle"),
color: "red", color: "red",
}); });
}, },
onSuccess: () => { onSuccess: () => {
notifications.show({ notifications.show({
title: "Logged out", title: t("logoutSuccessTitle"),
message: "Goodbye!", message: t("logoutSuccessSubtitle"),
color: "green", color: "green",
}); });
setTimeout(() => { setTimeout(() => {
@@ -43,13 +45,30 @@ export const LogoutPage = () => {
<Layout> <Layout>
<Paper shadow="md" p={30} mt={30} radius="md" withBorder> <Paper shadow="md" p={30} mt={30} radius="md" withBorder>
<Text size="xl" fw={700}> <Text size="xl" fw={700}>
Logout {t("logoutTitle")}
</Text> </Text>
<Text> <Text>
You are currently logged in as <Code>{username}</Code> {oauth ? (
{oauth && <Trans
` using ${capitalize(provider === "generic" ? genericName : provider)} OAuth`} i18nKey="logoutOauthSubtitle"
. Click the button below to log out. t={t}
components={{ Code: <Code /> }}
values={{
provider:
provider === "generic" ? genericName : capitalize(provider),
username: username,
}}
/>
) : (
<Trans
i18nKey="logoutUsernameSubtitle"
t={t}
components={{ Code: <Code /> }}
values={{
username: username,
}}
/>
)}
</Text> </Text>
<Button <Button
fullWidth fullWidth
@@ -57,7 +76,7 @@ export const LogoutPage = () => {
onClick={() => logoutMutation.mutate()} onClick={() => logoutMutation.mutate()}
loading={logoutMutation.isLoading} loading={logoutMutation.isLoading}
> >
Logout {t("logoutTitle")}
</Button> </Button>
</Paper> </Paper>
</Layout> </Layout>

View File

@@ -1,16 +1,18 @@
import { Button, Paper, Text } from "@mantine/core"; import { Button, Paper, Text } from "@mantine/core";
import { Layout } from "../components/layouts/layout"; import { Layout } from "../components/layouts/layout";
import { useTranslation } from "react-i18next";
export const NotFoundPage = () => { export const NotFoundPage = () => {
const { t } = useTranslation();
return ( return (
<Layout> <Layout>
<Paper shadow="md" p={30} mt={30} radius="md" withBorder> <Paper shadow="md" p={30} mt={30} radius="md" withBorder>
<Text size="xl" fw={700}> <Text size="xl" fw={700}>
Not found {t("notFoundTitle")}
</Text> </Text>
<Text>The page you are looking for does not exist.</Text> <Text>{t("notFoundSubtitle")}</Text>
<Button fullWidth mt="xl" onClick={() => window.location.replace("/")}> <Button fullWidth mt="xl" onClick={() => window.location.replace("/")}>
Go home {t("notFoundButton")}
</Button> </Button>
</Paper> </Paper>
</Layout> </Layout>

View File

@@ -7,6 +7,7 @@ import { useMutation } from "@tanstack/react-query";
import axios from "axios"; import axios from "axios";
import { notifications } from "@mantine/notifications"; import { notifications } from "@mantine/notifications";
import { useAppContext } from "../context/app-context"; import { useAppContext } from "../context/app-context";
import { useTranslation } from "react-i18next";
export const TotpPage = () => { export const TotpPage = () => {
const queryString = window.location.search; const queryString = window.location.search;
@@ -15,6 +16,7 @@ export const TotpPage = () => {
const { totpPending, isLoggedIn } = useUserContext(); const { totpPending, isLoggedIn } = useUserContext();
const { title } = useAppContext(); const { title } = useAppContext();
const { t } = useTranslation();
if (isLoggedIn) { if (isLoggedIn) {
return <Navigate to={`/logout`} />; return <Navigate to={`/logout`} />;
@@ -30,15 +32,15 @@ export const TotpPage = () => {
}, },
onError: () => { onError: () => {
notifications.show({ notifications.show({
title: "Failed to verify code", title: t("totpFailTitle"),
message: "Please try again", message: t("totpFailSubtitle"),
color: "red", color: "red",
}); });
}, },
onSuccess: () => { onSuccess: () => {
notifications.show({ notifications.show({
title: "Verified", title: t("totpSuccessTitle"),
message: "Redirecting to your app", message: t("totpSuccessSubtitle"),
color: "green", color: "green",
}); });
setTimeout(() => { setTimeout(() => {
@@ -52,7 +54,7 @@ export const TotpPage = () => {
<Title ta="center">{title}</Title> <Title ta="center">{title}</Title>
<Paper shadow="md" p="xl" mt={30} radius="md" withBorder> <Paper shadow="md" p="xl" mt={30} radius="md" withBorder>
<Text size="lg" fw={500} mb="md" ta="center"> <Text size="lg" fw={500} mb="md" ta="center">
Enter your TOTP code {t("totpTitle")}
</Text> </Text>
<TotpForm <TotpForm
isLoading={totpMutation.isLoading} isLoading={totpMutation.isLoading}

View File

@@ -2,6 +2,7 @@ import { Button, Code, Paper, Text } from "@mantine/core";
import { Layout } from "../components/layouts/layout"; import { Layout } from "../components/layouts/layout";
import { Navigate } from "react-router"; import { Navigate } from "react-router";
import { isQueryValid } from "../utils/utils"; import { isQueryValid } from "../utils/utils";
import { Trans, useTranslation } from "react-i18next";
export const UnauthorizedPage = () => { export const UnauthorizedPage = () => {
const queryString = window.location.search; const queryString = window.location.search;
@@ -9,6 +10,8 @@ export const UnauthorizedPage = () => {
const username = params.get("username") ?? ""; const username = params.get("username") ?? "";
const resource = params.get("resource") ?? ""; const resource = params.get("resource") ?? "";
const { t } = useTranslation();
if (!isQueryValid(username)) { if (!isQueryValid(username)) {
return <Navigate to="/" />; return <Navigate to="/" />;
} }
@@ -17,16 +20,26 @@ export const UnauthorizedPage = () => {
<Layout> <Layout>
<Paper shadow="md" p={30} mt={30} radius="md" withBorder> <Paper shadow="md" p={30} mt={30} radius="md" withBorder>
<Text size="xl" fw={700}> <Text size="xl" fw={700}>
Unauthorized {t("Unauthorized")}
</Text> </Text>
<Text> <Text>
The user with username <Code>{username}</Code> is not authorized to{" "}
{isQueryValid(resource) ? ( {isQueryValid(resource) ? (
<span> <Text>
access the <Code>{resource}</Code> resource. <Trans
</span> i18nKey="unauthorizedResourceSubtitle"
t={t}
components={{ Code: <Code /> }}
values={{ resource, username }}
/>
</Text>
) : ( ) : (
"login." <Text>
<Trans
i18nKey="unauthorizedLoginSubtitle"
t={t}
values={{ username }}
/>
</Text>
)} )}
</Text> </Text>
<Button <Button
@@ -34,7 +47,7 @@ export const UnauthorizedPage = () => {
mt="xl" mt="xl"
onClick={() => window.location.replace("/login")} onClick={() => window.location.replace("/login")}
> >
Try again {t("unauthorizedButton")}
</Button> </Button>
</Paper> </Paper>
</Layout> </Layout>