Skip to content

Commit b40e815

Browse files
committed
fix login page redirect
1 parent 5b9deca commit b40e815

File tree

3 files changed

+14
-16
lines changed

3 files changed

+14
-16
lines changed

packages/template-retail-react-app/app/hooks/use-auth-modal.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ export const AuthModal = ({
9393
const {getPasswordResetToken} = usePasswordReset()
9494
const authorizePasswordlessLogin = useAuthHelper(AuthHelpers.AuthorizePasswordless)
9595
const passwordlessConfigCallback = getConfig().app.login?.passwordless?.callbackURI
96+
const callbackURL = isAbsoluteURL(passwordlessConfigCallback)
97+
? passwordlessConfigCallback
98+
: `${appOrigin}${passwordlessConfigCallback}`
9699

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

110113
const handlePasswordlessLogin = async (email) => {
111114
try {
112-
const callbackURL = isAbsoluteURL(passwordlessConfigCallback)
113-
? passwordlessConfigCallback
114-
: `${appOrigin}${passwordlessConfigCallback}`
115-
const redirectPath = window.location.pathname
115+
const redirectPath = window.location.pathname + window.location.search
116116
await authorizePasswordlessLogin.mutateAsync({
117117
userid: email,
118118
callbackURI: `${callbackURL}?redirectUrl=${redirectPath}`

packages/template-retail-react-app/app/pages/checkout/partials/contact-info.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,13 @@ const ContactInfo = ({isSocialEnabled = false, isPasswordlessEnabled = false, id
8282
const authModal = useAuthModal(authModalView)
8383
const [isPasswordlessLoginClicked, setIsPasswordlessLoginClicked] = useState(false)
8484
const passwordlessConfigCallback = getConfig().app.login?.passwordless?.callbackURI
85+
const callbackURL = isAbsoluteURL(passwordlessConfigCallback)
86+
? passwordlessConfigCallback
87+
: `${appOrigin}${passwordlessConfigCallback}`
8588

8689
const handlePasswordlessLogin = async (email) => {
8790
try {
88-
const callbackURL = isAbsoluteURL(passwordlessConfigCallback)
89-
? passwordlessConfigCallback
90-
: `${appOrigin}${passwordlessConfigCallback}`
91-
const redirectPath = window.location.pathname
91+
const redirectPath = window.location.pathname + window.location.search
9292
await authorizePasswordlessLogin.mutateAsync({
9393
userid: email,
9494
callbackURI: `${callbackURL}?redirectUrl=${redirectPath}`

packages/template-retail-react-app/app/pages/login/index.jsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,9 @@ const Login = ({initialView = LOGIN_VIEW}) => {
151151
useEffect(() => {
152152
if (path === PASSWORDLESS_LOGIN_LANDING_PATH && isSuccessCustomerBaskets) {
153153
const token = decodeURIComponent(queryParams.get('token'))
154-
const redirect_url = decodeURIComponent(queryParams.get('redirect_url'))
155-
setRedirectPath(redirect_url)
154+
if (queryParams.get('redirect_url')) {
155+
setRedirectPath(decodeURIComponent(queryParams.get('redirect_url')))
156+
}
156157

157158
const passwordlessLogin = async () => {
158159
try {
@@ -173,12 +174,9 @@ const Login = ({initialView = LOGIN_VIEW}) => {
173174
useEffect(() => {
174175
if (isRegistered) {
175176
handleMergeBasket()
176-
if (redirectPath) {
177-
navigate(redirectPath)
178-
setRedirectPath('')
179-
} else {
180-
navigate('/account')
181-
}
177+
const redirectTo = redirectPath ? redirectPath : '/account'
178+
navigate(redirectTo)
179+
setRedirectPath('')
182180
}
183181
}, [isRegistered])
184182

0 commit comments

Comments
 (0)