Skip to content

Commit

Permalink
fix: log when incorrect and show error in login page (#1943)
Browse files Browse the repository at this point in the history
* feat: Add logs for incorrect AUTH_PROVIDER and show in login page

* feat: format any entry to lower case for AUTH_PROVIDER

* fix: Change simple text to Alert element on login page
  • Loading branch information
SeDemal authored Mar 9, 2024
1 parent 9c81d34 commit 9337914
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
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 @@ -19,6 +19,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 @@ -45,8 +46,22 @@ const env = createEnv({
// Authentication
AUTH_PROVIDER: z
.string()
.min(1)
.default('credentials')
.transform((providers) => providers.replaceAll(' ', '').split(',')),
.transform((providers) =>
providers
.replaceAll(' ', '')
.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

0 comments on commit 9337914

Please sign in to comment.