DEV Community

Zhiyuan Zhang
Zhiyuan Zhang

Posted on

Need Help: Login Kit not redirects to the my url properly

Here are my configuration:
Client-Id: 123123123
Callback Url: https://something.com/oauth/tiktok
Redirect Domain: something.com

Trigger the flow: https://something.com/oauth

If my TikTok account is logged in status, it will be redirected to my provided endpoint.
The problem is, when my TikTok account is not logged in, after logged in my TikTok account, it will redirect to TikTok homepage instead of my redirect url.
Can someone help review this and give me a hint, please?

const express = require('express');
const app = express();
const cookieParser = require('cookie-parser');
const cors = require('cors');

app.use(cookieParser());
app.use(cors());
app.listen(process.env.PORT || 80).

const CLIENT_KEY = '123123123' // this value can be found in app's developer portal
const SERVER_ENDPOINT_REDIRECT = 'https://something.com/oauth/tiktok'

app.get('/oauth', (req, res) => {
    const csrfState = Math.random().toString(36).substring(2);
    res.cookie('csrfState', csrfState, { maxAge: 60000 });

    let url = 'https://open-api.tiktok.com/platform/oauth/connect/';

    url += '?client_key=${CLIENT_KEY}';
    url += '&scope=user.info.basic';
    url += '&response_type=code';
    url += '&redirect_uri=${SERVER_ENDPOINT_REDIRECT}';
    url += '&state=' + csrfState;

    res.redirect(url);
})

app.get("/oauth/tiktok", (req, res) => {
  res.send("I got your token :-)!");
});
Enter fullscreen mode Exit fullscreen mode

Top comments (0)