Save JWT to user on login

This commit is contained in:
Alex Holliday committed 2024-08-09 13:14:20 -07:00
1 parent 62ce8e33b6
commit 5b2a05bc79
2 files changed
+5

No files matched your search

+2
View File
@@ -142,6 +142,8 @@ const loginController = async (req, res, next) => {
// Happy path, return token
const token = issueToken(userWithoutPassword);
user.authToken = token;
await user.save();
// reset avatar image
userWithoutPassword.avatarImage = user.avatarImage;
+3
View File
@@ -40,6 +40,9 @@ const UserSchema = mongoose.Schema(
default: "user",
enum: ["user", "admin"],
},
authToken: {
type: String,
},
},
{
timestamps: true,