Skip to content

Commit 49c2a65

Browse files
committed
Set next url for social login
1 parent 57ba2d9 commit 49c2a65

File tree

8 files changed

+43
-18
lines changed

8 files changed

+43
-18
lines changed

src/components/auth/AuthForm.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export interface AuthFormProps {
6262
onToggleMode: () => void;
6363
onSendAuthEmail: (email: string) => void;
6464
registered: boolean | null;
65+
currentPath: string;
6566
}
6667

6768
const AuthForm: React.FC<AuthFormProps> = ({
@@ -70,6 +71,7 @@ const AuthForm: React.FC<AuthFormProps> = ({
7071
onSendAuthEmail,
7172
loading,
7273
registered,
74+
currentPath,
7375
}) => {
7476
const [email, onChangeEmail] = useInput('');
7577
const onSubmit = (email: string) => {
@@ -98,7 +100,7 @@ const AuthForm: React.FC<AuthFormProps> = ({
98100
</section>
99101
<section>
100102
<h4>소셜 계정으로 {modeText}</h4>
101-
<AuthSocialButtonGroup />
103+
<AuthSocialButtonGroup currentPath={currentPath} />
102104
</section>
103105
</div>
104106
<div className="foot">

src/components/auth/AuthSocialButton.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const AuthSocialButtonBlock = styled.a<{ border: boolean }>`
2626
interface AuthSocialButtonProps {
2727
provider: 'facebook' | 'google' | 'github';
2828
tabIndex?: number;
29+
currentPath: string;
2930
}
3031

3132
const providerMap = {
@@ -49,6 +50,7 @@ const providerMap = {
4950
const AuthSocialButton: React.FC<AuthSocialButtonProps> = ({
5051
provider,
5152
tabIndex,
53+
currentPath,
5254
}) => {
5355
const info = providerMap[provider];
5456
const { icon: Icon, color, border } = info;
@@ -58,7 +60,7 @@ const AuthSocialButton: React.FC<AuthSocialButtonProps> = ({
5860
? process.env.REACT_APP_API_HOST
5961
: 'http://localhost:5000/';
6062

61-
const redirectTo = `${host}api/v2/auth/social/redirect/${provider}`;
63+
const redirectTo = `${host}api/v2/auth/social/redirect/${provider}?next=${currentPath}`;
6264

6365
return (
6466
<AuthSocialButtonBlock

src/components/auth/AuthSocialButtonGroup.tsx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,24 @@ const AuthSocialButtonGroupBlock = styled.div`
88
margin-top: 1.5rem;
99
`;
1010

11-
const AuthSocialButtonGroup = () => {
11+
const AuthSocialButtonGroup = ({ currentPath }: { currentPath: string }) => {
1212
return (
1313
<AuthSocialButtonGroupBlock>
14-
<AuthSocialButton provider="github" tabIndex={4} />
15-
<AuthSocialButton provider="google" tabIndex={5} />
16-
<AuthSocialButton provider="facebook" tabIndex={6} />
14+
<AuthSocialButton
15+
provider="github"
16+
tabIndex={4}
17+
currentPath={currentPath}
18+
/>
19+
<AuthSocialButton
20+
provider="google"
21+
tabIndex={5}
22+
currentPath={currentPath}
23+
/>
24+
<AuthSocialButton
25+
provider="facebook"
26+
tabIndex={6}
27+
currentPath={currentPath}
28+
/>
1729
</AuthSocialButtonGroupBlock>
1830
);
1931
};

src/components/auth/__tests__/AuthForm.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ describe('AuthForm', () => {
1111
onSendAuthEmail: (email: string) => {},
1212
loading: false,
1313
registered: null,
14+
currentPath: '/',
1415
};
1516
return render(<AuthForm {...initialProps} {...props} />);
1617
};

src/components/auth/__tests__/__snapshots__/AuthForm.test.tsx.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ exports[`AuthForm renders correctly 1`] = `
4343
>
4444
<a
4545
class="sc-bwzfXH dOnywA"
46-
href="http://localhost:5000/api/v2/auth/social/redirect/github"
46+
href="http://localhost:5000/api/v2/auth/social/redirect/github?next=/"
4747
style="background: rgb(39, 46, 51);"
4848
tabindex="4"
4949
>
@@ -53,7 +53,7 @@ exports[`AuthForm renders correctly 1`] = `
5353
</a>
5454
<a
5555
class="sc-bwzfXH fVlvjo"
56-
href="http://localhost:5000/api/v2/auth/social/redirect/google"
56+
href="http://localhost:5000/api/v2/auth/social/redirect/google?next=/"
5757
style="background: white;"
5858
tabindex="5"
5959
>
@@ -63,7 +63,7 @@ exports[`AuthForm renders correctly 1`] = `
6363
</a>
6464
<a
6565
class="sc-bwzfXH dOnywA"
66-
href="http://localhost:5000/api/v2/auth/social/redirect/facebook"
66+
href="http://localhost:5000/api/v2/auth/social/redirect/facebook?next=/"
6767
style="background: rgb(59, 89, 152);"
6868
tabindex="6"
6969
>

src/containers/auth/AuthModalContainer.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { connect } from 'react-redux';
1010
import { RootState } from '../../modules';
1111
import { sendAuthEmail, SendAuthEmailResponse } from '../../lib/api/auth';
1212
import useRequest from '../../lib/hooks/useRequest';
13+
import { useLocation } from 'react-router-dom';
1314

1415
interface OwnProps {}
1516
interface StateProps {
@@ -29,6 +30,7 @@ const AuthModalContainer: React.FC<AuthModalContainerProps> = ({
2930
closeAuthModal,
3031
changeAuthModalMode,
3132
}) => {
33+
const location = useLocation();
3234
const [_sendAuthEmail, loading, data, , resetSendAuthEmail] = useRequest<
3335
SendAuthEmailResponse
3436
>(sendAuthEmail);
@@ -60,6 +62,7 @@ const AuthModalContainer: React.FC<AuthModalContainerProps> = ({
6062
onSendAuthEmail={onSendAuthEmail}
6163
loading={loading}
6264
registered={registered}
65+
currentPath={`${location.pathname}${location.search}`}
6366
/>
6467
</AuthModal>
6568
);

src/containers/auth/__tests__/AuthModalContainer.test.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import rootReducer, { RootState } from '../../../modules';
55
import { Provider } from 'react-redux';
66
import { createStore } from 'redux';
77
import { showAuthModal } from '../../../modules/core';
8+
import { MemoryRouter } from 'react-router-dom';
89

910
describe('AuthForm', () => {
1011
const setupStore = () => {
@@ -16,9 +17,11 @@ describe('AuthForm', () => {
1617
const store = setupStore();
1718
store.dispatch(showAuthModal('REGISTER'));
1819
const { container } = render(
19-
<Provider store={store}>
20-
<AuthModalContainer />
21-
</Provider>,
20+
<MemoryRouter>
21+
<Provider store={store}>
22+
<AuthModalContainer />
23+
</Provider>
24+
</MemoryRouter>,
2225
);
2326
expect(container).toMatchSnapshot();
2427
});
@@ -27,9 +30,11 @@ describe('AuthForm', () => {
2730
const store = setupStore();
2831
store.dispatch(showAuthModal('REGISTER'));
2932
const { getByTestId } = render(
30-
<Provider store={store}>
31-
<AuthModalContainer />
32-
</Provider>,
33+
<MemoryRouter>
34+
<Provider store={store}>
35+
<AuthModalContainer />
36+
</Provider>
37+
</MemoryRouter>,
3338
);
3439
expect(getByTestId('title')).toHaveTextContent('회원가입');
3540
fireEvent.click(getByTestId('switchmode'));

src/containers/auth/__tests__/__snapshots__/AuthModalContainer.test.tsx.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ exports[`AuthForm renders correctly 1`] = `
8888
>
8989
<a
9090
class="sc-htpNat bNCvmd"
91-
href="http://localhost:5000/api/v2/auth/social/redirect/github"
91+
href="http://localhost:5000/api/v2/auth/social/redirect/github?next=/"
9292
style="background: rgb(39, 46, 51);"
9393
tabindex="4"
9494
>
@@ -98,7 +98,7 @@ exports[`AuthForm renders correctly 1`] = `
9898
</a>
9999
<a
100100
class="sc-htpNat bUuZiL"
101-
href="http://localhost:5000/api/v2/auth/social/redirect/google"
101+
href="http://localhost:5000/api/v2/auth/social/redirect/google?next=/"
102102
style="background: white;"
103103
tabindex="5"
104104
>
@@ -108,7 +108,7 @@ exports[`AuthForm renders correctly 1`] = `
108108
</a>
109109
<a
110110
class="sc-htpNat bNCvmd"
111-
href="http://localhost:5000/api/v2/auth/social/redirect/facebook"
111+
href="http://localhost:5000/api/v2/auth/social/redirect/facebook?next=/"
112112
style="background: rgb(59, 89, 152);"
113113
tabindex="6"
114114
>

0 commit comments

Comments
 (0)