Skip to content

fix: linotp support for logins#661

Merged
johbaxter merged 1 commit intodevfrom
659-login-page-doesnt-ever-show-linotp-login
Mar 4, 2025
Merged

fix: linotp support for logins#661
johbaxter merged 1 commit intodevfrom
659-login-page-doesnt-ever-show-linotp-login

Conversation

@antgibson96
Copy link
Copy Markdown
Contributor

No description provided.

@antgibson96 antgibson96 requested a review from a team as a code owner March 4, 2025 17:53
@antgibson96 antgibson96 linked an issue Mar 4, 2025 that may be closed by this pull request
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 4, 2025

@CodiumAI-Agent /describe

@QodoAI-Agent
Copy link
Copy Markdown

Title

fix: linotp support for logins


PR Type

  • Bug fix

Description

  • Normalize login type identifier from 'linOtp' to 'linotp'

  • Update union type and conditional checks for OTP login

  • Ensure consistent login provider naming across login flows


Changes walkthrough 📝

Relevant files
Bug fix
LoginPage.tsx
Normalize linotp login type usage                                               

packages/client/src/pages/LoginPage.tsx

  • Changed union type literal to 'linotp'
  • Updated object property checks for linotp
  • Modified conditional logic and state updates
  • Ensured consistency in login type selections
  • +7/-7     

    Need help?
  • Type /help how to ... in the comments thread for any questions about PR-Agent usage.
  • Check out the documentation for more information.
  • @github-actions
    Copy link
    Copy Markdown

    github-actions bot commented Mar 4, 2025

    @CodiumAI-Agent /review

    @QodoAI-Agent
    Copy link
    Copy Markdown

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Naming Consistency

    Verify that the updated login type string "linotp" is consistently integrated across the file. Ensure that all changes align with backend expectations and that no inconsistencies remain from the previous "linOtp" naming.

    'native' | 'ldap' | 'linotp' | ''
    Login Flow Update

    Confirm that the modifications in the login flow—especially the conditions for setting the login type and handling the OTP login—do not inadvertently affect other authentication paths. Ensure proper integration testing for scenarios involving multiple providers.

                if (loginType === 'linotp') {
                    await configStore
                        .loginOTP(data.USERNAME, data.PASSWORD)
                        .then(() => {
                            // noop
                            setShowOTPCodeField(true);
                        })
                        .catch((error) => {
                            setError(error.message);
                        })
                        .finally(() => {
                            // turn off loading
                            setIsLoading(false);
                        });
                }
            }
            if (showOTPCodeField) {
                await configStore
                    .confirmOTP(data.OTP_CONFIRM)
                    .then(() => {
                        // noop
                    })
                    .catch((error) => {
                        setError(error.message);
                    })
                    .finally(() => {
                        // turn off loading
                        setIsLoading(false);
                    });
                setShowOTPCodeField(true);
            }
        },
    );
    
    /**
     * Allow the user to login
     */
    const registerAccount = registerSubmit(
        async (data: TypeUserRegister): Promise<TypeUserRegister> => {
            // turn on loading
            setIsLoading(true);
    
            if (
                !data.USERNAME ||
                !data.PASSWORD ||
                !data.PASSWORD_CONFIRMATION ||
                !data.FIRST_NAME ||
                !data.LAST_NAME ||
                !data.EMAIL
            ) {
                setError(
                    'Username, password, password confirmation, email, first and last name are required',
                );
                setIsLoading(false);
                return;
            }
    
            if (data.PASSWORD !== data.PASSWORD_CONFIRMATION) {
                setError('Passwords do not match');
                setIsLoading(false);
                return;
            }
    
            await configStore
                .register(
                    `${data.FIRST_NAME} ${data.LAST_NAME}`,
                    data.USERNAME,
                    data.EMAIL,
                    data.PASSWORD,
                    data.PHONE,
                    data.EXTENTION,
                    data.COUNTRY_CODE,
                )
                .then((res) => {
                    if (res) {
                        setError('');
                        setRegister(false);
                        setSuccess(
                            'Account registration successful. Log in below.',
                        );
                    }
                })
                .catch((error) => {
                    setIsLoading(false);
                    setError(error.message);
                })
                .finally(() => {
                    // turn off loading
                    setIsLoading(false);
                });
        },
    );
    
    /**
     * Login with oauth
     * @param provider - provider to oauth with
     */
    const oauth = async (provider: string) => {
        // turn on loading
        setIsLoading(true);
    
        await configStore
            .oauth(provider)
            .then(() => {
                // turn off loading
                setIsLoading(false);
    
                // noop
                // (handled  by the configStore)
    
                setSnackbar({
                    open: true,
                    message: `Successfully logged in`,
                    color: 'success',
                });
            })
            .catch((error) => {
                // turn off loading
                setIsLoading(false);
    
                setError(error.message);
    
                setSnackbar({
                    open: true,
                    message: error.message,
                    color: 'error',
                });
            });
    };
    
    const themeMap = useMemo(() => {
        const theme = configStore.store.config['theme'];
    
        if (theme && theme['THEME_MAP']) {
            try {
                return JSON.parse(theme['THEME_MAP'] as string);
            } catch {
                return {};
            }
        }
    
        return {};
    }, [Object.keys(configStore.store.config).length]);
    
    // get the path the user is coming from
    const path = (location.state as { from: Location })?.from?.pathname || '/';
    
    // navigate if already logged in
    if (configStore.store.status === 'SUCCESS') {
        return <Navigate to={path} replace />;
    }
    
    return (
        <>
            <Snackbar
                open={snackbar.open}
                anchorOrigin={{ vertical: 'top', horizontal: 'right' }}
                autoHideDuration={6000}
                onClose={() => {
                    setSnackbar({
                        open: false,
                        message: '',
                        color: 'success',
                    });
                }}
            >
                <Alert severity={snackbar.color} sx={{ width: '100%' }}>
                    {snackbar.message}
                </Alert>
            </Snackbar>
            <StyledMain>
                <StyledRow>
                    <StyledScroll>
                        <StyledContent>
                            <div>
                                <StyledLogoBox>
                                    {themeMap.isLogoUrl ? (
                                        <StyledLogo src={themeMap.logo} />
                                    ) : THEME.logo ? (
                                        <StyledLogo src={THEME.logo} />
                                    ) : null}
                                    <StyledLogoText>
                                        {themeMap.name
                                            ? themeMap.name
                                            : THEME.name}
                                    </StyledLogoText>
                                </StyledLogoBox>
                                <Typography variant="h4">Welcome!</Typography>
                                <StyledInstructions variant="body1">
                                    {register
                                        ? 'Register below'
                                        : 'Log in below'}
                                </StyledInstructions>
                            </div>
                            {!register && hasMoreThanOneUserNamePassword && (
                                <StyledButtonGroup variant="outlined">
                                    {isNative && (
                                        <StyledButtonGroupItem
                                            onClick={() => {
                                                setLoginType('native');
                                                setSuccess('');
                                                setError('');
                                            }}
                                            selected={loginType === 'native'}
                                        >
                                            Native
                                        </StyledButtonGroupItem>
                                    )}
                                    {isLdap && (
                                        <StyledButtonGroupItem
                                            onClick={() => {
                                                setLoginType('ldap');
                                                setSuccess('');
                                                setError('');
                                            }}
                                            selected={loginType === 'ldap'}
                                        >
                                            LDAP
                                        </StyledButtonGroupItem>
                                    )}
                                    {isLinOTP && (
                                        <StyledButtonGroupItem
                                            onClick={() => {
                                                setLoginType('linotp');
                                                setSuccess('');
                                                setError('');
                                            }}
                                            selected={loginType === 'linotp'}
                                        >

    @github-actions
    Copy link
    Copy Markdown

    github-actions bot commented Mar 4, 2025

    @CodiumAI-Agent /improve

    @QodoAI-Agent
    Copy link
    Copy Markdown

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Impact
    General
    Use enum for login types

    Extract the login type string literals into a shared enum or constant to avoid
    potential case sensitivity and duplication issues across the component.

    packages/client/src/pages/LoginPage.tsx [247-250]

    -const [loginType, setLoginType] = useState<'native' | 'ldap' | 'linotp' | ''>('');
    +enum LoginType {
    +    NATIVE = 'native',
    +    LDAP = 'ldap',
    +    LINOTP = 'linotp',
    +    NONE = ''
    +}
    +const [loginType, setLoginType] = useState<LoginType>(LoginType.NONE);
    Suggestion importance[1-10]: 5

    __

    Why: While extracting login type literals into an enum would improve consistency and reduce chances for case mismatch issues, it only offers a moderate stylistic enhancement rather than fixing a critical bug.

    Low

    @johbaxter johbaxter merged commit 99bcc6c into dev Mar 4, 2025
    3 checks passed
    @johbaxter johbaxter deleted the 659-login-page-doesnt-ever-show-linotp-login branch March 4, 2025 19:06
    @github-actions
    Copy link
    Copy Markdown

    github-actions bot commented Mar 4, 2025

    @CodiumAI-Agent /update_changelog

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Labels

    None yet

    Projects

    None yet

    Development

    Successfully merging this pull request may close these issues.

    Login page doesn't ever show linotp login

    4 participants