Feathers: κ°€μž…κ³Ό 인증 κ²°ν•©

에 λ§Œλ“  2016λ…„ 12μ›” 27일  Β·  3μ½”λ©˜νŠΈ  Β·  좜처: feathersjs/feathers

인증 뒀에 μˆ¨μ€ 'λ§ˆλ²•'에 λŒ€ν•œ μ„€λͺ…이 λ³„λ‘œ μ—†λŠ” 것 κ°™μ•„μš”. λ‚΄ 등둝 μž‘μ—…μ„ κ²°ν•©ν•˜μ—¬ JWT 토큰을 λ°˜ν™˜ν•˜κ³  μ‹ΆμŠ΅λ‹ˆλ‹€. 아무도 λ‚˜λ₯Ό λ„μšΈ 수 μžˆμŠ΅λ‹ˆκΉŒ?

λ‚˜λŠ” 그것이 λ‹€μŒκ³Ό 같을 것이라고 μƒκ°ν•©λ‹ˆλ‹€.

  • 미듀웨어/signup.js
    ```js
    const μƒˆλ‘œμš΄ μ‚¬μš©μž = {
    μ‚¬μš©μž: req.body.user,
    패슀: req.body.pass
    }
    app.service('μ‚¬μš©μž').create(newUser)
    .then(user => app.authenticate(user)) // 인증은 μ •μ˜λ˜μ§€ μ•Šμ•˜μ§€λ§Œ
    .then(인증된 μ‚¬μš©μž => res.json(인증된 μ‚¬μš©μž));
    ````

λ§ˆλ²•μ˜ μ˜μ—­ λ°–μ—μ„œ 인증을 μ‚¬μš©ν•˜λŠ” 방법에 λŒ€ν•œ λ„μ›€μ΄λ‚˜ μ„€λͺ…을 얻을 수 μžˆμŠ΅λ‹ˆκΉŒ? 감사 ν•΄μš”!

νŽΈμ§‘: μˆ˜λ™ 인증에 λŒ€ν•œ 더 λ§Žμ€ λ¬Έμ„œκ°€ μžˆμ–΄μ•Ό ν•œλ‹€κ³  μƒκ°ν•˜κΈ° λ•Œλ¬Έμ— 이 문제λ₯Ό λ§Œλ“€μ—ˆμŠ΅λ‹ˆλ‹€. 이것은 데λͺ¨μ— κ°€κΉμŠ΅λ‹ˆλ‹€. 이미 #467κ³Ό 같은 λ¬Έμ œκ°€ μžˆλ‹€λŠ” 것을 μ•Œκ³  μžˆμŠ΅λ‹ˆλ‹€.

κ°€μž₯ μœ μš©ν•œ λŒ“κΈ€

μƒμ„±λœ 앱은 μ—¬μ „νžˆ ​​이전 인증을 μ‚¬μš©ν•˜μ§€λ§Œ 이 κ²½μš°μ—λŠ”

const { email, password } = req.body;

app.service('users').create({ email, password })
  .then(user => app.service('auth/local').create({ email, password }))
  .then(authenticatedUser => res.json(authenticatedUser));

λͺ¨λ“  3 λŒ“κΈ€

@rstegg 당신은 κ½€ κ°€κΉŒμš΄ 것 κ°™μŠ΅λ‹ˆλ‹€. app.authenticate() κ°€ μ •μ˜λ˜μ§€ μ•Šμ€ 경우 인증 ν”ŒλŸ¬κ·ΈμΈ 이전에 κ°€μž… 미듀웨어λ₯Ό μ‚¬μš© 쀑일 수 μžˆμŠ΅λ‹ˆλ‹€. λ¨Όμ € 인증 ν”ŒλŸ¬κ·ΈμΈμ΄ μ‚¬μš©λ˜λŠ”μ§€ ν™•μΈν•˜μ‹­μ‹œμ˜€.

const newUser = { 
  user: req.body.user,
  pass: req.body.pass
}
app.service('users').create(newUser)
  .then(user => app.authenticate(user)) // authenticate should be defined if you register middleware in the correct order.
  .then(jwt => res.json(jwt));

μƒμ„±λœ 앱은 μ—¬μ „νžˆ ​​이전 인증을 μ‚¬μš©ν•˜μ§€λ§Œ 이 κ²½μš°μ—λŠ”

const { email, password } = req.body;

app.service('users').create({ email, password })
  .then(user => app.service('auth/local').create({ email, password }))
  .then(authenticatedUser => res.json(authenticatedUser));

이 λ¬Έμ œλŠ” λ‹«νžŒ ν›„ 졜근 ν™œλ™μ΄ μ—†μ—ˆκΈ° λ•Œλ¬Έμ— μžλ™μœΌλ‘œ μž κ²ΌμŠ΅λ‹ˆλ‹€. κ΄€λ ¨ 버그에 λŒ€ν•œ 이 λ¬Έμ œμ— λŒ€ν•œ 링크λ₯Ό μ‚¬μš©ν•˜μ—¬ μƒˆ 문제λ₯Ό μ—¬μ‹­μ‹œμ˜€.

이 νŽ˜μ΄μ§€κ°€ 도움이 λ˜μ—ˆλ‚˜μš”?
0 / 5 - 0 λ“±κΈ‰