Skip to content

Commit 7e86976

Browse files
committed
chore: resolve redirect to callback problems
1 parent 6279922 commit 7e86976

File tree

4 files changed

+21
-5
lines changed

4 files changed

+21
-5
lines changed

src/app/[locale]/(auth)/account/signin/page.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,28 @@ const Page = () => {
4646

4747
const [isPending, startTransition] = useTransition();
4848

49+
const getCallbackUrl = () => {
50+
const callbackUrl =
51+
new URL(location.href).searchParams.get('callbackUrl') || '/';
52+
53+
const url = new URL(callbackUrl || '/');
54+
return url.pathname + url.search + url.hash;
55+
};
56+
4957
const onSubmit: SubmitHandler<FieldNames> = (data) => {
5058
startTransition(async () => {
51-
const callbackUrl =
52-
new URL(location.href).searchParams.get('callbackUrl') || '/';
59+
const callbackUrl = getCallbackUrl();
5360

5461
const result = await signIn('credentials', {
5562
...data,
56-
callbackUrl,
63+
redirect: false,
5764
});
5865

5966
if (result) {
6067
if (result.status !== 200) {
61-
toast.error(t('pages.error.message'));
68+
toast.error(t('messages.authenticationError'));
69+
} else {
70+
router.push(callbackUrl);
6271
}
6372
}
6473
});

src/app/[locale]/(main)/(container)/profile/page.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,12 @@ const Page = () => {
3636
<Menu />
3737
</MobileView>
3838
<DesktopView>
39-
<Card variant="outlined">
39+
<Card
40+
variant="outlined"
41+
sx={{
42+
flexGrow: 1,
43+
}}
44+
>
4045
<CardContent>
4146
<CardHeader title={t('profile.latestOrders')}>
4247
{!!edges?.length && (

src/data/i18n/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"title": "Are you sure?"
55
},
66
"messages": {
7+
"authenticationError": "Authentication Error",
78
"passwordNotMatch": "Passwords must match",
89
"copied": "Copied to clipboard",
910
"cart": {

src/data/i18n/fa.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"title": "آیا مطمئن هستید؟"
55
},
66
"messages": {
7+
"authenticationError": "نام کاربری یا رمز عبور اشتباه است.",
78
"passwordNotMatch": "تایید رمز عبور با رمز عبور مطابقت ندارد.",
89
"copied": "کپی شد.",
910
"cart": {

0 commit comments

Comments
 (0)