Skip to content

Commit

Permalink
fix login page redirect
Browse files Browse the repository at this point in the history
yunakim714 committed Jan 30, 2025

Verified

This commit was signed with the committer’s verified signature.
yunakim714 Yuna Kim
1 parent 5b9deca commit b40e815
Showing 3 changed files with 14 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -93,6 +93,9 @@ export const AuthModal = ({
const {getPasswordResetToken} = usePasswordReset()
const authorizePasswordlessLogin = useAuthHelper(AuthHelpers.AuthorizePasswordless)
const passwordlessConfigCallback = getConfig().app.login?.passwordless?.callbackURI
const callbackURL = isAbsoluteURL(passwordlessConfigCallback)
? passwordlessConfigCallback
: `${appOrigin}${passwordlessConfigCallback}`

const {data: baskets} = useCustomerBaskets(
{parameters: {customerId}},
@@ -109,10 +112,7 @@ export const AuthModal = ({

const handlePasswordlessLogin = async (email) => {
try {
const callbackURL = isAbsoluteURL(passwordlessConfigCallback)
? passwordlessConfigCallback
: `${appOrigin}${passwordlessConfigCallback}`
const redirectPath = window.location.pathname
const redirectPath = window.location.pathname + window.location.search
await authorizePasswordlessLogin.mutateAsync({
userid: email,
callbackURI: `${callbackURL}?redirectUrl=${redirectPath}`
Original file line number Diff line number Diff line change
@@ -82,13 +82,13 @@ const ContactInfo = ({isSocialEnabled = false, isPasswordlessEnabled = false, id
const authModal = useAuthModal(authModalView)
const [isPasswordlessLoginClicked, setIsPasswordlessLoginClicked] = useState(false)
const passwordlessConfigCallback = getConfig().app.login?.passwordless?.callbackURI
const callbackURL = isAbsoluteURL(passwordlessConfigCallback)
? passwordlessConfigCallback
: `${appOrigin}${passwordlessConfigCallback}`

const handlePasswordlessLogin = async (email) => {
try {
const callbackURL = isAbsoluteURL(passwordlessConfigCallback)
? passwordlessConfigCallback
: `${appOrigin}${passwordlessConfigCallback}`
const redirectPath = window.location.pathname
const redirectPath = window.location.pathname + window.location.search
await authorizePasswordlessLogin.mutateAsync({
userid: email,
callbackURI: `${callbackURL}?redirectUrl=${redirectPath}`
14 changes: 6 additions & 8 deletions packages/template-retail-react-app/app/pages/login/index.jsx
Original file line number Diff line number Diff line change
@@ -151,8 +151,9 @@ const Login = ({initialView = LOGIN_VIEW}) => {
useEffect(() => {
if (path === PASSWORDLESS_LOGIN_LANDING_PATH && isSuccessCustomerBaskets) {
const token = decodeURIComponent(queryParams.get('token'))
const redirect_url = decodeURIComponent(queryParams.get('redirect_url'))
setRedirectPath(redirect_url)
if (queryParams.get('redirect_url')) {
setRedirectPath(decodeURIComponent(queryParams.get('redirect_url')))
}

const passwordlessLogin = async () => {
try {
@@ -173,12 +174,9 @@ const Login = ({initialView = LOGIN_VIEW}) => {
useEffect(() => {
if (isRegistered) {
handleMergeBasket()
if (redirectPath) {
navigate(redirectPath)
setRedirectPath('')
} else {
navigate('/account')
}
const redirectTo = redirectPath ? redirectPath : '/account'
navigate(redirectTo)
setRedirectPath('')
}
}, [isRegistered])

0 comments on commit b40e815

Please sign in to comment.