sourcecode

Nuxt SSR에서 여권 js 리다이렉트를 처리하려면 어떻게 해야 합니까?

copyscript 2022. 7. 27. 23:52
반응형

Nuxt SSR에서 여권 js 리다이렉트를 처리하려면 어떻게 해야 합니까?

익스프레스 세션에서 Nuxt SSR를 사용하고 있으며 서버 측에서 JS 리다이렉트 패스포트를 가지고 있습니다.

/**
 * POST /signup
 * Create a new local account.
 */
exports.postSignup = (req, res, next) => {
  const validationErrors = [];
  if (!validator.isEmail(req.body.email)) validationErrors.push({ msg: 'Please enter a valid email address.' });
  if (!validator.isLength(req.body.password, { min: 8 })) validationErrors.push({ msg: 'Password must be at least 8 characters long' });
  if (req.body.password !== req.body.confirmPassword) validationErrors.push({ msg: 'Passwords do not match' });

  if (validationErrors.length) {
    req.flash('errors', validationErrors);
    return res.redirect('/signup');
  }
  req.body.email = validator.normalizeEmail(req.body.email, { gmail_remove_dots: false });

  const user = new User({
    email: req.body.email,
    password: req.body.password
  });

  User.findOne({ email: req.body.email }, (err, existingUser) => {
    if (err) { return next(err); }
    if (existingUser) {
      req.flash('errors', { msg: 'Account with that email address already exists.' });
      return res.redirect('/signup');
    }
    user.save((err) => {
      if (err) { return next(err); }
      req.logIn(user, (err) => {
        if (err) {
          return next(err);
        }
        res.redirect('/');
      });
    });
  });
};

리다이렉트 메서드를 호출하면?페이지를 새로고침하여 Vuex 상태를 클리어할 수 있습니다.Vuex 상태가 그대로 유지되고 클라이언트 페이지가 새로 고쳐지지 않도록 여권에서 이 리다이렉트를 수행하려면 어떻게 해야 합니다.

@Darius가 언급한 바와 같이 페이지 새로 고침을 피하려면 폼 제출을 비동기적으로 처리하는 것이 좋습니다.그러나 완성을 위해 vuex-peristed state와 같은 Vuex 상태를 유지하기 위한 솔루션이 존재함을 알려드리고 싶습니다.localStorage, sessionStorage 또는 쿠키에 상태를 유지하는 데 사용할 수 있습니다.Nuxt 플러그인으로도 사용할 수 있습니다.

언급URL : https://stackoverflow.com/questions/59510939/how-do-i-handle-passport-js-redirects-from-nuxt-ssr

반응형