mako4kamiya / reflection-app

0 stars 0 forks source link

- JWT Auth - #77

Closed mako4kamiya closed 3 years ago

mako4kamiya commented 3 years ago

jsonwebtoken bcryptjs追加

mako4kamiya commented 3 years ago

Role model の追加

module.exports = mongoose => {
    const Role = mongoose.model(
        "role",
        mongoose.Schema(
        {
            name: String
        })
    );

    return Role;
};

これと

const mongoose = require("mongoose");

const Role = mongoose.model(
  "Role",
  new mongoose.Schema({
    name: String
  })
);

module.exports = Role;

これの違いはなんだ。。。

mako4kamiya commented 3 years ago

User modelの編集

module.exports = mongoose => {
    const User = mongoose.model(
        "User",
        mongoose.Schema(
        {
            name: String,
            password: String,
            roles: [
                {
                    type: mongoose.Schema.Types.ObjectId,
                    ref: "Role"
                }
            ]},
        { timestamps: true }
        )
    );
    return User;
};

Roleオブジェクトを参照する

mako4kamiya commented 3 years ago

Configure Auth Key

mako4kamiya commented 3 years ago

Create Middleware functions