Skip to content

Commit 6279922

Browse files
committed
feat: complete callback url of sign-in and auth client
1 parent d6b9c97 commit 6279922

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+519
-582
lines changed

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"commitlint",
1313
"deepmerge",
1414
"ecommerce",
15+
"hookform",
1516
"iranyekanwebboldfanum",
1617
"muirtl",
1718
"nextauth",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"jotai": "^2.8.1",
2929
"js-cookie": "^3.0.5",
3030
"material-ui-confirm": "^3.0.7",
31-
"next": "14.2.20",
31+
"next": "14.2.22",
3232
"next-auth": "^4.24.10",
3333
"next-intl": "^3.11.1",
3434
"react": "^18",

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

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
'use client';
22

3+
import PasswordTextField from '@/components/PasswordTextField/PasswordTextField';
34
import ButtonWithLoading from '@/components/common/ButtonWithLoading';
45
import Logo from '@/components/common/Logo';
56
import { Link, useRouter } from '@/navigation';
67
import { yupResolver } from '@hookform/resolvers/yup';
7-
import { Box, Stack, TextField, Typography } from '@mui/material';
8+
import {
9+
Box,
10+
Link as MuiLink,
11+
Stack,
12+
TextField,
13+
Typography,
14+
} from '@mui/material';
815
import Card from '@mui/material/Card';
916
import CardActions from '@mui/material/CardActions';
1017
import CardContent from '@mui/material/CardContent';
@@ -14,7 +21,6 @@ import { useTransition } from 'react';
1421
import { Controller, SubmitHandler, useForm } from 'react-hook-form';
1522
import { toast } from 'react-hot-toast';
1623
import * as yup from 'yup';
17-
import { Link as MuiLink } from '@mui/material';
1824

1925
type FieldNames = Partial<Record<'username' | 'password', any>>;
2026

@@ -42,16 +48,17 @@ const Page = () => {
4248

4349
const onSubmit: SubmitHandler<FieldNames> = (data) => {
4450
startTransition(async () => {
51+
const callbackUrl =
52+
new URL(location.href).searchParams.get('callbackUrl') || '/';
53+
4554
const result = await signIn('credentials', {
4655
...data,
47-
redirect: false,
56+
callbackUrl,
4857
});
4958

5059
if (result) {
5160
if (result.status !== 200) {
52-
toast.error('An Error Occurred!');
53-
} else {
54-
router.push('/');
61+
toast.error(t('pages.error.message'));
5562
}
5663
}
5764
});
@@ -102,10 +109,12 @@ const Page = () => {
102109
value={value}
103110
variant="outlined"
104111
fullWidth
105-
dir="ltr"
106-
placeholder={labels[name]}
112+
label={labels[name]}
107113
error={!!error?.message}
108114
helperText={error?.message?.toString()}
115+
inputProps={{
116+
dir: 'ltr',
117+
}}
109118
/>
110119
);
111120
}}
@@ -118,15 +127,13 @@ const Page = () => {
118127
fieldState: { error },
119128
}) => {
120129
return (
121-
<TextField
122-
type="password"
130+
<PasswordTextField
123131
onChange={onChange}
124132
name={name}
125133
value={value}
126134
variant="outlined"
127135
fullWidth
128-
dir="ltr"
129-
placeholder={labels[name]}
136+
label={labels[name]}
130137
error={!!error?.message}
131138
helperText={error?.message?.toString()}
132139
/>

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

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use client';
22

3+
import PasswordTextField from '@/components/PasswordTextField/PasswordTextField';
34
import ButtonWithLoading from '@/components/common/ButtonWithLoading';
45
import Logo from '@/components/common/Logo';
56
import { REGISTER_CUSTOMER } from '@/graphql/queries/auth';
@@ -36,11 +37,12 @@ const Page = () => {
3637
};
3738
const resolveSchema: yup.ObjectSchema<FieldNames> = yup.object({
3839
email: yup.string().email().nullable().required().label(labels.email),
39-
password: yup.string().nullable().required().label(labels.password),
40+
password: yup.string().min(6).nullable().required().label(labels.password),
4041
confirmPassword: yup
4142
.string()
4243
.nullable()
4344
.required()
45+
.oneOf([yup.ref('password')], t('messages.passwordNotMatch'))
4446
.label(labels.confirmPassword),
4547
firstName: yup.string().nullable().required().label(labels.firstName),
4648
lastName: yup.string().nullable().required().label(labels.lastName),
@@ -198,8 +200,7 @@ const Page = () => {
198200
fieldState: { error },
199201
}) => {
200202
return (
201-
<TextField
202-
type="password"
203+
<PasswordTextField
203204
onChange={onChange}
204205
name={name}
205206
value={value}
@@ -208,10 +209,6 @@ const Page = () => {
208209
label={labels[name]}
209210
error={!!error?.message}
210211
helperText={error?.message?.toString()}
211-
inputProps={{
212-
autoComplete: 'new-password',
213-
dir: 'ltr',
214-
}}
215212
/>
216213
);
217214
}}
@@ -226,8 +223,7 @@ const Page = () => {
226223
fieldState: { error },
227224
}) => {
228225
return (
229-
<TextField
230-
type="password"
226+
<PasswordTextField
231227
onChange={onChange}
232228
name={name}
233229
value={value}
@@ -236,10 +232,6 @@ const Page = () => {
236232
label={labels[name]}
237233
error={!!error?.message}
238234
helperText={error?.message?.toString()}
239-
inputProps={{
240-
autoComplete: 'new-password',
241-
dir: 'ltr',
242-
}}
243235
/>
244236
);
245237
}}

src/app/[locale]/(auth)/layout.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
'use client';
2+
3+
import { MobileFooter } from '@/components/Footer/components';
14
import { DesktopView, MobileView } from '@/components/ResponsiveDesign';
25
import { Grid, Stack } from '@mui/material';
36
import { FC, ReactNode } from 'react';
47
import Back from './components/Back/Back';
5-
import { MobileFooter } from '@/components/Footer/components';
68

79
export interface AuthLayoutProps {
810
children: ReactNode;

src/app/[locale]/(auth)/loading.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
Stack,
88
} from '@mui/material';
99

10-
const loading = () => {
10+
const Loading = () => {
1111
return (
1212
<Card
1313
variant="outlined"
@@ -39,4 +39,4 @@ const loading = () => {
3939
);
4040
};
4141

42-
export default loading;
42+
export default Loading;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import SimpleLoading from '@/components/SimpleLoading/SimpleLoading';
2+
3+
const Loading = () => {
4+
return <SimpleLoading />;
5+
};
6+
7+
export default Loading;

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ import DiscountCode from '../cart/components/DiscountCode';
3838
import AvailablePaymentGateways from './components/AvailablePaymentGateways';
3939
import AvailableShippingMethods from './components/AvailableShippingMethods';
4040
import Billing from './components/Billing';
41+
import { authClient } from '@/graphql/clients/authClient';
42+
import Loading from './loading';
4143

4244
const Page = () => {
4345
const t = useTranslations();
@@ -62,15 +64,27 @@ const Page = () => {
6264
}, []);
6365

6466
const [updateShippingMethod, { loading: shippingMethodLoading }] =
65-
useMutation<UpdateShippingMethodMutation>(UPDATE_SHIPPING_METHOD);
67+
useMutation<UpdateShippingMethodMutation>(UPDATE_SHIPPING_METHOD, {
68+
client: authClient,
69+
});
6670

6771
const [checkout, { loading: checkoutLoading }] =
68-
useMutation<CheckoutMutation>(CHECKOUT_MUTATION);
72+
useMutation<CheckoutMutation>(CHECKOUT_MUTATION, {
73+
client: authClient,
74+
});
6975

7076
const [emptyCartMutate, { loading: emptyCartLoading }] =
71-
useMutation<RemoveItemsFromCartMutation>(EMPTY_CART_MUTATION);
77+
useMutation<RemoveItemsFromCartMutation>(EMPTY_CART_MUTATION, {
78+
client: authClient,
79+
});
80+
81+
if (!content?.contents?.itemCount) {
82+
if (loading || content === null) {
83+
return <Loading />;
84+
}
7285

73-
if (!content?.contents?.itemCount) return redirect('/cart');
86+
return redirect('/cart');
87+
}
7488

7589
const rates = content?.availableShippingMethods?.flatMap((item) => {
7690
return item?.rates;

src/app/[locale]/(main)/(container)/products/[...params]/components/ProductTabs.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@ const ProductTabs: FC<ProductTabsProps> = ({ content, attributes }) => {
2424
attributes
2525
?.filter((item) => !item.variation)
2626
.map((item) => {
27-
const value = item.optionNames?.join(`${t('stringSeparator')} `) ?? '';
27+
const value =
28+
item.terms?.nodes
29+
.map((item) => item.name)
30+
?.join(`${t('stringSeparator')} `) ?? '';
2831
return {
2932
key: item.label ?? '',
3033
value,
3134
};
3235
}) ?? [];
33-
console.log('🚀 ~ items:', items);
3436

3537
return (
3638
<>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ const getProduct = async ({ id }: { id: number }) => {
4141
variables: {
4242
id,
4343
},
44-
fetchPolicy: 'no-cache',
4544
});
46-
return data.product;
45+
46+
return data?.product || { __typename: 'SimpleProduct' };
4747
};
4848

4949
const Page: FC<PageProps> = async ({ params: { params } }) => {

0 commit comments

Comments
 (0)