-
Notifications
You must be signed in to change notification settings - Fork 597
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1413 from deepfence/ui-v2-login-handler-refactor
Refactor login and signup response handle
- Loading branch information
Showing
4 changed files
with
36 additions
and
44 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { redirect } from 'react-router-dom'; | ||
|
||
import { ModelLoginResponse } from '@/api/generated'; | ||
import { validateRedirectToUrl } from '@/utils/api'; | ||
import storage from '@/utils/storage'; | ||
|
||
export function handleLoginAndRedirect( | ||
loginResponse: ModelLoginResponse, | ||
searchParams?: URLSearchParams, | ||
): never { | ||
storage.setAuth({ | ||
accessToken: loginResponse.access_token, | ||
refreshToken: loginResponse.refresh_token, | ||
}); | ||
|
||
if (loginResponse.onboarding_required) { | ||
throw redirect('/onboard', 302); | ||
} | ||
|
||
const redirectTo = searchParams?.get('redirectTo'); | ||
if (redirectTo && validateRedirectToUrl(redirectTo)) { | ||
throw redirect(redirectTo, 302); | ||
} | ||
|
||
throw redirect('/dashboard', 302); | ||
} |