nulab / backlog-js

Backlog API version 2 client for browser and node.
https://developer.nulab-inc.com/docs/backlog/
33 stars 13 forks source link

Form data is not defined #33

Closed huu-md closed 3 years ago

huu-md commented 3 years ago

Hello. I using a code example for oauth2. After I click allow and redirect to my web. This is my function handled callback.

app.get('/callback', async (req, res) => {
    const code = req.query.code;
    try {
        const accessToken = await oauth2.getAccessToken({ host, code, redirectUri });
        console.log('Access Token:', accessToken);

        // save access token.

        const myself = await new backlogjs.Backlog({
            host, accessToken: accessToken.access_token
        }).getMyself();
        console.log('Myself:', myself);

        res.redirect('/');
    } catch (e) {
        console.log('Access Token Error:', e.message);
        res.redirect('/login');
    }
});

I got an error: Access Token Error: FormData is not defined. This exception throw in this line: const accessToken = await oauth2.getAccessToken({ host, code, redirectUri });

mmktomato commented 3 years ago

Could you try to add this line? You may need isomorphic-form-data package.

import 'isomorphic-form-data';
// or require('isomorphic-form-data');
huu-md commented 3 years ago

Could you try to add this line? You may need isomorphic-form-data package.

import 'isomorphic-form-data';
// or require('isomorphic-form-data');

Oh thank you so much