Skip to content

web_trouble_shooting

sang-gyeong lee edited this page Dec 20, 2020 · 1 revision

Next.js ์‚ฌ์šฉ์‹œ styled components ์Šคํƒ€์ผ์ด ์ ์šฉ์ „์— ๋ Œ๋”๊ฐ€ ๋˜๋Š” ๋ฌธ์ œ๋ฐœ์ƒ

-> Next.js ๊ณต์‹๋ฌธ์„œ๋ฅผ ์ฐธ๊ณ ํ•˜์—ฌ _document.tsx ํŒŒ์ผ์„ ์ปค์Šคํ…€ ํ•˜์—ฌ ํ•ด๊ฒฐํ•จ

๋ฃจํŠธ ํŒŒ์ผ์— .babelrc ํŒŒ์ผ ๋งŒ๋“ค๊ธฐ

{
  "presets": [
    "next/babel"
  ],
  "plugins": [
    [
      "styled-components",
      {
        "ssr": true,
        "displayName": true,
        "preprocess": false
      }
    ]
  ]
}

Create the _document.js file pages ํด๋” ์•„๋ž˜์— _document.js ์ƒ์„ฑ

import Document, { Head, Main, NextScript } from 'next/document';
// Import styled components ServerStyleSheet
import { ServerStyleSheet } from 'styled-components';

export default class MyDocument extends Document {
  static getInitialProps({ renderPage }) {
    // Step 1: Create an instance of ServerStyleSheet
    const sheet = new ServerStyleSheet();

    // Step 2: Retrieve styles from components in the page
    const page = renderPage((App) => (props) =>
      sheet.collectStyles(<App {...props} />),
    );

    // Step 3: Extract the styles as <style> tags
    const styleTags = sheet.getStyleElement();

    // Step 4: Pass styleTags as a prop
    return { ...page, styleTags };
  }

  render() {
    return (
      <html>
        <Head>
          <title>My page</title>
          {/* Step 5: Output the styles in the head  */}
          {this.props.styleTags}
        </Head>
        <body>
          <Main />
          <NextScript />
        </body>
      </html>
    );
  }
}

์ฐธ๊ณ  https://dev.to/aprietof/nextjs--styled-components-the-really-simple-guide----101c


cookie ์ ‘๊ทผ๋ฌธ์ œ

  • ๋ฌธ์ œ์ƒํ™ฉ : ์—”ํŠธ๋ฆฌ ํŒŒ์ผ์—์„œ switch route ๋ถ„๊ธฐ์ฒ˜๋ฆฌ ๋ถ€๋ถ„์—์„œ ๋กœ์ปฌ์Šคํ† ๋ฆฌ์ง€์™€ ์ฟ ํ‚ค์— ์ ‘๊ทผํ•˜์—ฌ ์œ ์ €์˜ ๋กœ๊ทธ์ธ ์—ฌ๋ถ€๋ฅผ ํŒ๋ณ„ํ•˜์˜€๋˜
    ๊ธฐ์กด์˜ ๋ฆฌ์•กํŠธ ํ”„๋กœ์ ํŠธ์™€ ๋‹ฌ๋ฆฌ, next.js์—์„œ ์ฟ ํ‚ค ๋ฐ ๋กœ์ปฌ ์Šคํ„ฐ๋ฆฌ์ง€์— ์ ‘๊ทผํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์ฐพ์ง€ ๋ชปํ•ด ์–ด๋ ค์›€์„ ๊ฒช์—ˆ๋‹ค.
    • getServersideProps๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ req.headers.cookie๋กœ ์ฟ ํ‚ค์— ์ ‘๊ทผํ•˜๋Š” ๊ฒƒ์— ์„ฑ๊ณตํ•˜์˜€๋‹ค.
    • ์„œ๋ฒ„์—์„œ ์–ป์€ ์ฟ ํ‚ค๋ฅผ ํด๋ผ์ด์–ธํŠธ์— ๋„˜๊ฒจ์ฃผ๊ณ , api.default.headers.authorization์— ํ•ด๋‹น ์ฟ ํ‚ค๋ฅผ ๋„ฃ๋Š” ๋ฐฉ๋ฒ•์œผ๋กœ ํ—ค๋”์— ์ฟ ํ‚ค๋ฅผ ๋„ฃ์„ ์ˆ˜ ์žˆ์—ˆ๋‹ค.

iOS์™€ pc ๋ถ„๊ธฐ์ฒ˜๋ฆฌ ๋ฌธ์ œ

  • ๋ฌธ์ œ์ƒํ™ฉ : iOS ํŒ€๊ณผ์˜ ํ˜‘์—… ์ค‘, iPad๋ฅผ user-agent์—์„œ ๊ตฌ๋ถ„ํ•˜์ง€ ๋ชปํ•˜๋Š” ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•˜์˜€๋‹ค.
    • iPad๊ฐ€ ๋ฒ„์ „ ์—…๋ฐ์ดํŠธ ๋˜๋ฉด์„œ ์›น๊ณผ ๊ฑฐ์˜ ์œ ์‚ฌํ•œ uger-agent๋ฅผ ๋ณด์˜€๊ธฐ ๋•Œ๋ฌธ์— ๋ถ„๊ธฐ์ฒ˜๋ฆฌ์— ์–ด๋ ค์›€์„ ๋Š๊ผˆ๋‹ค.
    • ๊ฒฐ๊ตญ auth2๋ผ๋Š” ์ƒˆ๋กœ์šด API๋ฅผ ๋งŒ๋“ค์–ด ๋ชจ๋ฐ”์ผ ํŒ€์— ์ „๋‹ฌํ•จ์œผ๋กœ์จ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜์˜€๋‹ค.

Clone this wiki locally