Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AUTH_PROVIDER log when incorrect and show error in login page #1943

Merged
merged 3 commits into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion public/locales/en/authentication/login.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
"buttons": {
"submit": "Sign in"
},
"afterLoginRedirection": "After login, you'll be redirected to {{url}}"
"afterLoginRedirection": "After login, you'll be redirected to {{url}}",
"providersEmpty": {
"title": "Auth Provider Error",
"message": "The provider(s) are unset, please check your logs for more information."
}
},
"alert": "Your credentials are incorrect or this account doesn't exist. Please try again."
}
17 changes: 16 additions & 1 deletion src/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const portSchema = z
.optional();
const envSchema = z.enum(['development', 'test', 'production']);

const validAuthProviders = ['credentials', 'ldap', 'oidc'];
const authProviders = process.env.AUTH_PROVIDER?.replaceAll(' ', '').split(',') || ['credentials'];

const env = createEnv({
Expand All @@ -43,8 +44,22 @@ const env = createEnv({
// Authentication
AUTH_PROVIDER: z
.string()
.min(1)
.default('credentials')
.transform((providers) => providers.replaceAll(' ', '').split(',')),
.transform((providers) =>
providers
.replaceAll(' ', '')
SeDemal marked this conversation as resolved.
Show resolved Hide resolved
.toLowerCase()
.split(',')
.filter((provider) => {
if (validAuthProviders.includes(provider)) return provider;
else if (!provider)
console.log(
`One or more of the entries for AUTH_PROVIDER could not be parsed and/or returned null.`
);
else console.log(`The value entered for AUTH_PROVIDER "${provider}" is incorrect.`);
})
),
// LDAP
...(authProviders.includes('ldap')
? {
Expand Down
16 changes: 13 additions & 3 deletions src/pages/auth/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,19 @@ export default function LoginPage({
{t('title')}
</Title>

<Text color="dimmed" size="sm" align="center" mt={5} mb="md">
{t('text')}
</Text>
{(providers.length < 1 && (
<Alert
icon={<IconAlertTriangle size="1rem" />}
title={t('form.providersEmpty.title')}
mt={5}
>
{t('form.providersEmpty.message')}
</Alert>
)) || (
<Text color="dimmed" size="sm" align="center" mt={5} mb="md">
{t('text')}
</Text>
)}

{isError && (
<Alert icon={<IconAlertTriangle size="1rem" />} color="red">
Expand Down
Loading