diff --git a/src/components/editor/Editor.tsx b/src/components/editor/Editor.tsx index c062b26..52e25cd 100644 --- a/src/components/editor/Editor.tsx +++ b/src/components/editor/Editor.tsx @@ -52,11 +52,18 @@ import { CustomTableCell } from './customComponent/CustomTableCell'; import CustomTextStyle from './customComponent/CustomTextStyle'; import { CustomTable } from './customComponent/CustomTable'; import CustomOembed from './customComponent/CustomOembed'; +import { jwtDecode } from '../../utils/jwtDecode'; const Editor = ({ content }: { content: JSONContent[] | null }) => { + // 토큰을 가져와 디코딩하여 사용자 닉네임을 가져와서 authorName에 넣어준다. + const token = localStorage.getItem('token'); + const decodedToken = jwtDecode(token); + const authorName = decodedToken.nickname; + decodedToken.nickname = authorName; + const [articleData, setArticleData] = useState({ title: '', - authorName: 'none', + authorName: authorName, categoryName: 'none', type: 'none', paywallUp: '', @@ -364,4 +371,4 @@ const Editor = ({ content }: { content: JSONContent[] | null }) => { ); }; -export default Editor; +export default Editor; \ No newline at end of file diff --git a/src/components/editor/PreviewComponrnt.tsx b/src/components/editor/PreviewComponrnt.tsx index eba0ae0..4811a99 100644 --- a/src/components/editor/PreviewComponrnt.tsx +++ b/src/components/editor/PreviewComponrnt.tsx @@ -131,7 +131,7 @@ const PreviewComponent: React.FC = ({ {new Date().toLocaleDateString()}
BY. {authorName}

-
+
{!isPremium ? ( <>
diff --git a/src/components/editor/common/extractPaywallData.ts b/src/components/editor/common/extractPaywallData.ts index d18ff43..6392dd6 100644 --- a/src/components/editor/common/extractPaywallData.ts +++ b/src/components/editor/common/extractPaywallData.ts @@ -107,8 +107,20 @@ const extractPaywallData = (editor: Editor): PaywallData => { paywallDown = convertToHTML(content.slice(index + 1)); } - if (!imageLink && node.type === 'photo' && node.attrs?.src) { - imageLink = node.attrs.src; + if (!imageLink) { + if (node.type === 'photo' && node.attrs?.src) { + imageLink = node.attrs.src; + } else if ( + (node.type === 'photoGroup' || node.type === 'photoStrip') && + node.content + ) { + const firstImgNode = node.content.find( + (childNode) => childNode.type === 'image', + ); + if (firstImgNode && firstImgNode.attrs?.src) { + imageLink = firstImgNode.attrs.src; + } + } } }); diff --git a/src/utils/jwtDecode.ts b/src/utils/jwtDecode.ts new file mode 100644 index 0000000..9fa595c --- /dev/null +++ b/src/utils/jwtDecode.ts @@ -0,0 +1,14 @@ +export const jwtDecode = (token: string | null) => { + if (!token) return null; + + const base64Url = token.split('.')[1]; + const base64 = base64Url.replace('-', '+').replace('_', '/'); + const jsonPayload = decodeURIComponent( + atob(base64) + .split('') + .map((c) => '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2)) + .join('') + ); + + return JSON.parse(jsonPayload); +} \ No newline at end of file