Skip to content

Commit 6c90046

Browse files
committed
feat: add option to disable ui warnings
1 parent 22a2ab3 commit 6c90046

11 files changed

Lines changed: 43 additions & 60 deletions

File tree

cmd/root.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ func (c *rootCmd) Register() {
7171
{"disable-analytics", false, "Disable anonymous version collection."},
7272
{"disable-resources", false, "Disable the resources server."},
7373
{"socket-path", "", "Path to the Unix socket to bind the server to."},
74+
{"disable-ui-warnings", false, "Disable UI warnings about insecure configurations."},
7475
}
7576

7677
for _, opt := range configOptions {

frontend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "tinyauth-shadcn",
2+
"name": "tinyauth",
33
"private": true,
44
"version": "0.0.0",
55
"type": "module",

frontend/src/components/layout/layout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const BaseLayout = ({ children }: { children: React.ReactNode }) => {
3131
};
3232

3333
export const Layout = () => {
34-
const { appUrl } = useAppContext();
34+
const { appUrl, disableUiWarnings } = useAppContext();
3535
const [ignoreDomainWarning, setIgnoreDomainWarning] = useState(() => {
3636
return window.sessionStorage.getItem("ignoreDomainWarning") === "true";
3737
});
@@ -42,7 +42,7 @@ export const Layout = () => {
4242
setIgnoreDomainWarning(true);
4343
}, [setIgnoreDomainWarning]);
4444

45-
if (!ignoreDomainWarning && appUrl !== currentUrl) {
45+
if (!ignoreDomainWarning && !disableUiWarnings && appUrl !== currentUrl) {
4646
return (
4747
<BaseLayout>
4848
<DomainWarning

frontend/src/lib/hooks/use-is-mounted.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.

frontend/src/pages/continue-page.tsx

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { Navigate, useLocation, useNavigate } from "react-router";
1414
import { useEffect, useState } from "react";
1515

1616
export const ContinuePage = () => {
17-
const { cookieDomain } = useAppContext();
17+
const { cookieDomain, disableUiWarnings } = useAppContext();
1818
const { isLoggedIn } = useUserContext();
1919
const { search } = useLocation();
2020
const { t } = useTranslation();
@@ -53,12 +53,16 @@ export const ContinuePage = () => {
5353
};
5454

5555
useEffect(() => {
56+
if (!isLoggedIn) {
57+
return;
58+
}
59+
5660
if (
57-
!isLoggedIn ||
58-
!isValidRedirectUri ||
59-
!isTrustedRedirectUri ||
60-
!isAllowedRedirectProto ||
61-
isHttpsDowngrade
61+
(!isValidRedirectUri ||
62+
!isAllowedRedirectProto ||
63+
!isTrustedRedirectUri ||
64+
isHttpsDowngrade) &&
65+
!disableUiWarnings
6266
) {
6367
return;
6468
}
@@ -76,14 +80,7 @@ export const ContinuePage = () => {
7680
clearTimeout(auto);
7781
clearTimeout(reveal);
7882
};
79-
}, [
80-
handleRedirect,
81-
isAllowedRedirectProto,
82-
isHttpsDowngrade,
83-
isLoggedIn,
84-
isTrustedRedirectUri,
85-
isValidRedirectUri,
86-
]);
83+
}, []);
8784

8885
if (!isLoggedIn) {
8986
return (
@@ -98,7 +95,7 @@ export const ContinuePage = () => {
9895
return <Navigate to="/logout" replace />;
9996
}
10097

101-
if (!isTrustedRedirectUri) {
98+
if (!isTrustedRedirectUri && !disableUiWarnings) {
10299
return (
103100
<Card role="alert" aria-live="assertive" className="min-w-xs sm:min-w-sm">
104101
<CardHeader>
@@ -136,7 +133,7 @@ export const ContinuePage = () => {
136133
);
137134
}
138135

139-
if (isHttpsDowngrade) {
136+
if (isHttpsDowngrade && !disableUiWarnings) {
140137
return (
141138
<Card role="alert" aria-live="assertive" className="min-w-xs sm:min-w-sm">
142139
<CardHeader>

frontend/src/pages/login-page.tsx

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import { OAuthButton } from "@/components/ui/oauth-button";
1818
import { SeperatorWithChildren } from "@/components/ui/separator";
1919
import { useAppContext } from "@/context/app-context";
2020
import { useUserContext } from "@/context/user-context";
21-
import { useIsMounted } from "@/lib/hooks/use-is-mounted";
2221
import { LoginSchema } from "@/schemas/login-schema";
2322
import { useMutation } from "@tanstack/react-query";
2423
import axios, { AxiosError } from "axios";
@@ -40,7 +39,6 @@ export const LoginPage = () => {
4039
const { providers, title, oauthAutoRedirect } = useAppContext();
4140
const { search } = useLocation();
4241
const { t } = useTranslation();
43-
const isMounted = useIsMounted();
4442
const [oauthAutoRedirectHandover, setOauthAutoRedirectHandover] =
4543
useState(false);
4644
const [showRedirectButton, setShowRedirectButton] = useState(false);
@@ -112,31 +110,20 @@ export const LoginPage = () => {
112110
});
113111

114112
useEffect(() => {
115-
if (isMounted()) {
116-
if (
117-
oauthProviders.length !== 0 &&
118-
providers.find((provider) => provider.id === oauthAutoRedirect) &&
119-
!isLoggedIn &&
120-
redirectUri
121-
) {
122-
// Not sure of a better way to do this
123-
// eslint-disable-next-line react-hooks/set-state-in-effect
124-
setOauthAutoRedirectHandover(true);
125-
oauthMutation.mutate(oauthAutoRedirect);
126-
redirectButtonTimer.current = window.setTimeout(() => {
127-
setShowRedirectButton(true);
128-
}, 5000);
129-
}
113+
if (
114+
providers.find((provider) => provider.id === oauthAutoRedirect) &&
115+
!isLoggedIn &&
116+
redirectUri
117+
) {
118+
// Not sure of a better way to do this
119+
// eslint-disable-next-line react-hooks/set-state-in-effect
120+
setOauthAutoRedirectHandover(true);
121+
oauthMutation.mutate(oauthAutoRedirect);
122+
redirectButtonTimer.current = window.setTimeout(() => {
123+
setShowRedirectButton(true);
124+
}, 5000);
130125
}
131-
}, [
132-
isMounted,
133-
oauthProviders.length,
134-
providers,
135-
isLoggedIn,
136-
redirectUri,
137-
oauthAutoRedirect,
138-
oauthMutation,
139-
]);
126+
}, []);
140127

141128
useEffect(
142129
() => () => {

frontend/src/schemas/app-context-schema.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export const appContextSchema = z.object({
1414
forgotPasswordMessage: z.string(),
1515
backgroundImage: z.string(),
1616
oauthAutoRedirect: z.string(),
17+
disableUiWarnings: z.boolean(),
1718
});
1819

1920
export type AppContextSchema = z.infer<typeof appContextSchema>;

internal/bootstrap/app_bootstrap.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ func (app *BootstrapApp) Setup() error {
236236
ForgotPasswordMessage: app.config.ForgotPasswordMessage,
237237
BackgroundImage: app.config.BackgroundImage,
238238
OAuthAutoRedirect: app.config.OAuthAutoRedirect,
239+
DisableUIWarnings: app.config.DisableUIWarnings,
239240
}, apiRouter)
240241

241242
oauthController := controller.NewOAuthController(controller.OAuthControllerConfig{

internal/config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ type Config struct {
4141
TrustedProxies string `mapstructure:"trusted-proxies"`
4242
DisableAnalytics bool `mapstructure:"disable-analytics"`
4343
DisableResources bool `mapstructure:"disable-resources"`
44+
DisableUIWarnings bool `mapstructure:"disable-ui-warnings"`
4445
SocketPath string `mapstructure:"socket-path"`
4546
}
4647

internal/controller/context_controller.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type AppContextResponse struct {
3232
ForgotPasswordMessage string `json:"forgotPasswordMessage"`
3333
BackgroundImage string `json:"backgroundImage"`
3434
OAuthAutoRedirect string `json:"oauthAutoRedirect"`
35+
DisableUIWarnings bool `json:"disableUiWarnings"`
3536
}
3637

3738
type Provider struct {
@@ -48,6 +49,7 @@ type ContextControllerConfig struct {
4849
ForgotPasswordMessage string
4950
BackgroundImage string
5051
OAuthAutoRedirect string
52+
DisableUIWarnings bool
5153
}
5254

5355
type ContextController struct {
@@ -56,6 +58,10 @@ type ContextController struct {
5658
}
5759

5860
func NewContextController(config ContextControllerConfig, router *gin.RouterGroup) *ContextController {
61+
if config.DisableUIWarnings {
62+
log.Warn().Msg("UI warnings are disabled. This may expose users to security risks. Proceed with caution.")
63+
}
64+
5965
return &ContextController{
6066
config: config,
6167
router: router,
@@ -117,5 +123,6 @@ func (controller *ContextController) appContextHandler(c *gin.Context) {
117123
ForgotPasswordMessage: controller.config.ForgotPasswordMessage,
118124
BackgroundImage: controller.config.BackgroundImage,
119125
OAuthAutoRedirect: controller.config.OAuthAutoRedirect,
126+
DisableUIWarnings: controller.config.DisableUIWarnings,
120127
})
121128
}

0 commit comments

Comments
 (0)