-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Simplify useAuth storage and only use local storage - Load useBlueprint only in one place
- Loading branch information
1 parent
54b6f51
commit 81b2074
Showing
16 changed files
with
178 additions
and
287 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,10 @@ | ||
import { useEffect } from 'react'; | ||
import { useNavigate, useSearchParams } from 'react-router-dom'; | ||
|
||
import { useAuth } from '@novu/shared-web'; | ||
import { LoginForm } from './components/LoginForm'; | ||
import AuthContainer from '../../components/layout/components/AuthContainer'; | ||
import { useVercelIntegration, useBlueprint, useVercelParams } from '../../hooks'; | ||
import SetupLoader from './components/SetupLoader'; | ||
import { useSegment } from '../../components/providers/SegmentProvider'; | ||
import { useAcceptInvite } from './components/useAcceptInvite'; | ||
import { ROUTES } from '../../constants/routes.enum'; | ||
import AuthLayout from '../../components/layout/components/AuthLayout'; | ||
|
||
export default function LoginPage() { | ||
useBlueprint(); | ||
const { login, token: oldToken, currentUser, claims } = useAuth(); | ||
const segment = useSegment(); | ||
const navigate = useNavigate(); | ||
const [params] = useSearchParams(); | ||
const queryToken = params.get('token'); | ||
const invitationToken = params.get('invitationToken'); | ||
const source = params.get('source'); | ||
const sourceWidget = params.get('source_widget'); | ||
const token = queryToken ?? oldToken; | ||
|
||
const { startVercelSetup, isLoading } = useVercelIntegration(); | ||
const { code, isFromVercel, next } = useVercelParams(); | ||
const { isLoading: isLoadingAcceptInvite, submitToken } = useAcceptInvite(); | ||
|
||
useEffect(() => { | ||
if (token) { | ||
if (!invitationToken && currentUser?._id && (!claims?.organizationId || !claims?.environmentId)) { | ||
const authApplicationLink = isFromVercel | ||
? `${ROUTES.AUTH_APPLICATION}?code=${code}&next=${next}` | ||
: ROUTES.AUTH_APPLICATION; | ||
login(token); | ||
navigate(authApplicationLink); | ||
|
||
return; | ||
} | ||
|
||
if (isFromVercel) { | ||
login(token); | ||
startVercelSetup(); | ||
|
||
return; | ||
} | ||
|
||
if (source === 'cli') { | ||
segment.track('Dashboard Visit', { | ||
widget: sourceWidget || 'unknown', | ||
source: 'cli', | ||
}); | ||
login(token); | ||
navigate(ROUTES.GET_STARTED); | ||
|
||
return; | ||
} | ||
|
||
if (invitationToken) { | ||
submitToken(token, invitationToken); | ||
|
||
return; | ||
} | ||
|
||
login(token); | ||
navigate('/'); | ||
} | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [token]); | ||
|
||
return isLoading || isLoadingAcceptInvite ? ( | ||
<SetupLoader title="Loading..." /> | ||
) : ( | ||
<AuthContainer title="Sign In" description="Welcome back! Sign in with the data you entered in your registration"> | ||
return ( | ||
<AuthLayout title="Sign In" description="Welcome back!"> | ||
<LoginForm /> | ||
</AuthContainer> | ||
</AuthLayout> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,35 @@ | ||
import { useParams, useNavigate } from 'react-router-dom'; | ||
import { useState } from 'react'; | ||
import AuthContainer from '../../components/layout/components/AuthContainer'; | ||
import AuthLayout from '../../components/layout/components/AuthLayout'; | ||
import { PasswordResetRequestForm } from './components/PasswordResetRequestForm'; | ||
import { PasswordResetForm } from './components/PasswordResetForm'; | ||
import { Button } from '@novu/design-system'; | ||
import { ROUTES } from '../../constants/routes.enum'; | ||
import { useVercelParams } from '../../hooks'; | ||
|
||
type Props = {}; | ||
|
||
export function PasswordResetPage({}: Props) { | ||
export function PasswordResetPage() { | ||
const navigate = useNavigate(); | ||
const { token } = useParams<{ token: string }>(); | ||
const [showSentSuccess, setShowSentSuccess] = useState<boolean>(); | ||
const { isFromVercel, code, next, configurationId } = useVercelParams(); | ||
const { isFromVercel, params } = useVercelParams(); | ||
|
||
const vercelQueryParams = `code=${code}&next=${next}&configurationId=${configurationId}`; | ||
const loginLink = isFromVercel ? `/auth/login?${vercelQueryParams}` : ROUTES.AUTH_LOGIN; | ||
function onSent() { | ||
setShowSentSuccess(true); | ||
} | ||
const loginLink = isFromVercel ? `${ROUTES.AUTH_LOGIN}?${params.toString()}` : ROUTES.AUTH_LOGIN; | ||
|
||
return showSentSuccess ? ( | ||
<AuthContainer | ||
if (showSentSuccess) { | ||
<AuthLayout | ||
title="Reset Sent!" | ||
description="We've sent a password reset link to the account associated with your email" | ||
> | ||
<Button data-test-id="success-screen-reset" onClick={() => navigate(loginLink)} inherit> | ||
Go Back | ||
</Button> | ||
</AuthContainer> | ||
) : ( | ||
<AuthContainer title="Reset Password" description=""> | ||
{!token && <PasswordResetRequestForm onSent={onSent} />} | ||
</AuthLayout>; | ||
} | ||
|
||
return ( | ||
<AuthLayout title="Reset Password" description=""> | ||
{!token && <PasswordResetRequestForm onSent={() => setShowSentSuccess(true)} />} | ||
{token && <PasswordResetForm token={token} />} | ||
</AuthContainer> | ||
</AuthLayout> | ||
); | ||
} |
Oops, something went wrong.