最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

我的 Javascript 项目中出现“SyntaxError: Unexpected token } in JSON at position 63”,我不知道该怎么办?

网站源码admin27浏览0评论

我的 Javascript 项目中出现“SyntaxError: Unexpected token } in JSON at position 63”,我不知道该怎么办?

我的 Javascript 项目中出现“SyntaxError: Unexpected token } in JSON at position 63”,我不知道该怎么办?

SyntaxError: Unexpected token } in JSON at position 63
    at JSON.parse (<anonymous>)
    at parse (C:\LEARN\javascript-projects\fullstack-auth\backend\node_modules\body-parser\lib\types\json.js:89:19)    
    at C:\LEARN\javascript-projects\fullstack-auth\backend\node_modules\body-parser\lib\read.js:128:18
    at AsyncResource.runInAsyncScope (node:async_hooks:203:9)
    at invokeCallback (C:\LEARN\javascript-projects\fullstack-auth\backend\node_modules\raw-body\index.js:231:16)      
    at done (C:\LEARN\javascript-projects\fullstack-auth\backend\node_modules\raw-body\index.js:220:7)
    at IncomingMessage.onEnd (C:\LEARN\javascript-projects\fullstack-auth\backend\node_modules\raw-body\index.js:280:7)
    at IncomingMessage.emit (node:events:513:28)
    at endReadableNT (node:internal/streams/readable:1359:12)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

当我尝试为我的学习项目创建一个登录 API 时出现了这个问题。 这是我的代码,

import user from "../models/userModel.js";
import argon2 from "argon2";

export const Login = async(req, res) => {
    const a_user = await user.findOne({
        where: {
            email: req.body.email
        }
    });
    if(!a_user) return res.status(404).json({msg: "User tidak ditemukan!"});
    const match = await argon2.verify(a_user.password, req.body.password);
    if(!match) return res.status(400).json({msg: "Wrong Password"});
    req.session.userId = a_user.uuid;
    const uuid = a_user.uuid;
    const name = a_user.name;
    const email = a_user.email;
    const role = a_user.role;
    res.status(200).json({uuid, name, email, role});
}

export const Me = async(req, res) => {
    if(!req.session.userId){
        return res.status(401).json({msg: "Mohon login ke akun anda!"});
    }
    const a_user = await user.findOne({
        attributes:['uuid','name','email','role'],
        where: {
            uuid: req.session.userId
        }
    });
    if(!a_user) return res.status(404).json({msg: "User tidak ditemukan!"});
    res.status(200).json(a_user);
}

export const Logout = (req, res) => {
    req.session.destroy((err)=>{
        if(err) return res.status(400).json({msg: "Tidak dapat logout"});
        res.status(200).json({msg: "Anda telah logout!"});
    });
}

我尝试仔细检查我的代码,但没有问题。

回答如下:
发布评论

评论列表(0)

  1. 暂无评论