Skip to content

로그인 필요한 페이지에서 로그인 안내 문구 #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ const userResolvers: Resolvers = {
checkEmailExists: async (_, { input }) => {
const userService = container.resolve(UserService)
const user = await userService.findByEmail(input.email)
console.log('user', user)
return !!user
},
},
Expand Down
12 changes: 6 additions & 6 deletions packages/velog-server/src/services/UserService/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,13 +242,13 @@ export class UserService implements Service {
try {
if (ENV.dockerEnv === 'development') {
console.log(`Login URL: ${ENV.clientV3Host}/email-change?code=${code}`)
} else {
await this.mail.sendMail({
to: email,
from: '[email protected]',
...template,
})
}

await this.mail.sendMail({
to: email,
from: '[email protected]',
...template,
})
} catch (error) {
console.error('change email error', error)
throw error
Expand Down
7 changes: 4 additions & 3 deletions packages/velog-server/src/template/changeEmailTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ export const changeEmailTemplate: ChangeEmailTemplateArgs = (username, email, co
<a href="https://velog.io">
<img src="https://images.velog.io/email-logo.png" style="display: block; width: 128px; margin: 0 auto;"/>
</a>
<div style="max-width: 100%; width: 400px; margin: 0 auto; padding: 1rem; text-align: justify; background: #f8f9fa; border: 1px solid #dee2e6; box-sizing: border-box; border-radius: 4px; color: #868e96; margin-top: 0.5rem; box-sizing: border-box;">
<b style="black">안녕하세요!</b>
${username}의 이메일을 ${email}${text}하는 것을 승인하겠습니까?
<div style="max-width: 100%; margin: 0 auto; padding: 1rem; text-align: justify; background: #f8f9fa; border: 1px solid #dee2e6; box-sizing: border-box; border-radius: 4px; color: #868e96; margin-top: 0.5rem; box-sizing: border-box;">
<div><b style="black">안녕하세요!</b></div>
<p style="word-wrap: break-word; word-break: break-all;">${username}의 이메일을 ${email}${text}하는 것을 승인하겠습니까?</p>
</div>
<a href="${endpoint}/email-change?code=${code}" style="text-decoration: none; width: 400px; text-align:center; display:block; margin: 0 auto; margin-top: 1rem; background: #845ef7; padding-top: 1rem; color: white; font-size: 1.25rem; padding-bottom: 1rem; font-weight: 600; border-radius: 4px;">
${text}하기
Expand All @@ -25,6 +25,7 @@ export const changeEmailTemplate: ChangeEmailTemplateArgs = (username, email, co
</div>
</div>
`

return {
subject,
body,
Expand Down
4 changes: 2 additions & 2 deletions packages/velog-web/src/app/notifications/page.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import RequireLogin from '@/components/RequireLogin'
import NotificationList from '@/features/notification/components/NotificationList'
import NotificationSelector from '@/features/notification/components/NotificationSelector'
import NotificationTitle from '@/features/notification/components/NotificationTitle'
import getCurrentUser from '@/prefetch/getCurrentUser'
import { notFound } from 'next/navigation'

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

if (!user) {
notFound()
return <RequireLogin />
}

return (
Expand Down
3 changes: 2 additions & 1 deletion packages/velog-web/src/app/setting/page.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import RequireLogin from '@/components/RequireLogin'
import SettingEmailRow from '@/features/setting/components/SettingEmailRow'
import SettingEmailRulesRow from '@/features/setting/components/SettingEmailRulesRow'
import SettingSocialInfoRow from '@/features/setting/components/SettingSocialInfoRow'
Expand All @@ -13,7 +14,7 @@ export default async function SettingPage() {
const user = await getCurrentUser()

if (!user) {
notFound()
return <RequireLogin />
}

const velogConfig = await getVelogConfig({ username: user.username })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
display: flex;
width: 100%;
height: 100%;
min-height: 100svh;
align-items: center;
justify-content: center;
flex-direction: column;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.block {
height: 70svh;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import RequireLogin from './RequireLogin'
import { render } from '@testing-library/react'

describe('RequireLogin', () => {
it('renders successfully', () => {
render(<RequireLogin />)
})
})
50 changes: 50 additions & 0 deletions packages/velog-web/src/components/RequireLogin/RequireLogin.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
'use client'

import styles from './RequireLogin.module.css'
import { bindClassNames } from '@/lib/styles/bindClassNames'
import ErrorScreenTemplate from '@/components/Error/ErrorScreenTemplate'
import { UndrawLogin } from '@/assets/vectors/components'
import { useModal } from '@/state/modal'
import { useEffect } from 'react'
import { useAuth } from '@/state/auth'
import { usePathname, useRouter } from 'next/navigation'

const cx = bindClassNames(styles)

type Props = {
redirectTo?: string
}

function RequireLogin({ redirectTo }: Props) {
const pathname = usePathname()
const router = useRouter()
const { actions } = useModal()

const redirectToPath = redirectTo || pathname

const {
value: { currentUser },
} = useAuth()

const onButtonClick = () => {
actions.showModal('login', redirectToPath)
}

useEffect(() => {
if (!currentUser) return
router.push(redirectToPath)
}, [router, currentUser, redirectToPath])

return (
<div className={cx('block')}>
<ErrorScreenTemplate
Illustration={UndrawLogin}
message="로그인 후 이용해주세요."
onButtonClick={onButtonClick}
buttonText="로그인"
/>
</div>
)
}

export default RequireLogin
1 change: 1 addition & 0 deletions packages/velog-web/src/components/RequireLogin/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './RequireLogin'