1

I'm pretty sure It's because ctx.render function is just for rendering page, but I have no idea what to do to do what I'm tryna do.

Basically, I'm trying to redirect user to user's mypage after login, with jwt token in the header so I used axios to send get request to server, and the server router function renders dynamic pug file with given data. I want to put jwt data into pug file but when I send get request, the page only just refreshes itself and doesn't actually redirect to mypage.

Here's code

client

try {
    let res = await axios(loginOpt)
    await store.set('jwtToken', res.data.token)
    let mpOpt = {headers: {"Authorization": 'Bearer ' + store.get('jwtToken')}}
    axios.get(`/u/${payload.email}`, mpOpt)
} catch (e) {
    console.error("failed to send login request", e)
}

router

router.get('/:userName', async (ctx, next) => {
    console.log("jwt TOKEN IS", ctx.header.authorization)

    let renderData = {
        userName: userName,
        profilePic: "../images/1.mesege_1.png",
        itemCount: itemCount.data,
        contentCount: itemCount.data, 
        joinedDate: m(dateString).format('LL'),
        lastVisited: m(dateString).format('LL') // gotta add
    }

    await ctx.render('form/form4', renderData)
})
Phillip YS
  • 784
  • 3
  • 10
  • 33

0 Answers0