Skip to content

Commit 90b7f60

Browse files
committed
Merge branch 'feature/require-login' into development
2 parents 77e5d16 + 7e492fb commit 90b7f60

File tree

7 files changed

+66
-4
lines changed

7 files changed

+66
-4
lines changed

packages/velog-web/src/app/notifications/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1+
import RequireLogin from '@/components/RequireLogin'
12
import NotificationList from '@/features/notification/components/NotificationList'
23
import NotificationSelector from '@/features/notification/components/NotificationSelector'
34
import NotificationTitle from '@/features/notification/components/NotificationTitle'
45
import getCurrentUser from '@/prefetch/getCurrentUser'
5-
import { notFound } from 'next/navigation'
66

77
export default async function NotificationPage() {
88
const user = await getCurrentUser()
99

1010
if (!user) {
11-
notFound()
11+
return <RequireLogin />
1212
}
1313

1414
return (

packages/velog-web/src/app/setting/page.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import RequireLogin from '@/components/RequireLogin'
12
import SettingEmailRow from '@/features/setting/components/SettingEmailRow'
23
import SettingEmailRulesRow from '@/features/setting/components/SettingEmailRulesRow'
34
import SettingSocialInfoRow from '@/features/setting/components/SettingSocialInfoRow'
@@ -13,7 +14,7 @@ export default async function SettingPage() {
1314
const user = await getCurrentUser()
1415

1516
if (!user) {
16-
notFound()
17+
return <RequireLogin />
1718
}
1819

1920
const velogConfig = await getVelogConfig({ username: user.username })

packages/velog-web/src/components/Error/ErrorScreenTemplate/ErrorScreenTemplate.module.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
display: flex;
33
width: 100%;
44
height: 100%;
5-
min-height: 100svh;
65
align-items: center;
76
justify-content: center;
87
flex-direction: column;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.block {
2+
height: 70svh;
3+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import RequireLogin from './RequireLogin'
2+
import { render } from '@testing-library/react'
3+
4+
describe('RequireLogin', () => {
5+
it('renders successfully', () => {
6+
render(<RequireLogin />)
7+
})
8+
})
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
'use client'
2+
3+
import styles from './RequireLogin.module.css'
4+
import { bindClassNames } from '@/lib/styles/bindClassNames'
5+
import ErrorScreenTemplate from '@/components/Error/ErrorScreenTemplate'
6+
import { UndrawLogin } from '@/assets/vectors/components'
7+
import { useModal } from '@/state/modal'
8+
import { useEffect } from 'react'
9+
import { useAuth } from '@/state/auth'
10+
import { usePathname, useRouter } from 'next/navigation'
11+
12+
const cx = bindClassNames(styles)
13+
14+
type Props = {
15+
redirectTo?: string
16+
}
17+
18+
function RequireLogin({ redirectTo }: Props) {
19+
const pathname = usePathname()
20+
const router = useRouter()
21+
const { actions } = useModal()
22+
23+
const redirectToPath = redirectTo || pathname
24+
25+
const {
26+
value: { currentUser },
27+
} = useAuth()
28+
29+
const onButtonClick = () => {
30+
actions.showModal('login', redirectToPath)
31+
}
32+
33+
useEffect(() => {
34+
if (!currentUser) return
35+
router.push(redirectToPath)
36+
}, [router, currentUser, redirectToPath])
37+
38+
return (
39+
<div className={cx('block')}>
40+
<ErrorScreenTemplate
41+
Illustration={UndrawLogin}
42+
message="로그인 후 이용해주세요."
43+
onButtonClick={onButtonClick}
44+
buttonText="로그인"
45+
/>
46+
</div>
47+
)
48+
}
49+
50+
export default RequireLogin
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from './RequireLogin'

0 commit comments

Comments
 (0)