LeeviHalme / node-steam-openid

A wrapper package around Steam's Authentication API. Supports promises :)
MIT License
51 stars 10 forks source link

[NestJs]: node_steam_openid_1.default is not a construct #18

Open Izakun opened 10 months ago

Izakun commented 10 months ago

Hello,

May be i'm dumb (that's probably true). Ill try to configure node_steam_openid on a NestJs projet but i got this error : ERROR [ExceptionHandler] node_steam_openid_1.default is not a constructor

My service :

import {Injectable} from '@nestjs/common';
import SteamAuth from 'node-steam-openid';

@Injectable()
export class SteamAuthService {
    private readonly steam: SteamAuth;

    constructor() {
        this.steam = new SteamAuth({
            realm: 'http://localhost:3000',
            returnUrl: 'http://localhost:3000auth/steam/callback',
            apiKey: 'AZERTYUIOP123456789',
        });
    }

    async getRedirectUrl(): Promise<string> {
        return await this.steam.getRedirectUrl(); // Renvoie l'URL d'authentification Steam
    }

    async authenticate(req: any): Promise<UserObject> {
        try {
            return await this.steam.authenticate(req)

            //...do something with the data
        } catch (error) {
            console.error(error);
        }
    }
}

And my controller :

import {Controller, Get, Redirect, Req, Res} from '@nestjs/common';
import {SteamAuthService} from "./steam-auth.service";

@Controller('auth/steam')
export class SteamAuthController {
    constructor(private readonly steamAuthService: SteamAuthService) {}
    @Get()
    async redirectToSteamLogin(@Res() res: any): Promise<void> {
        const redirectUrl = this.steamAuthService.getRedirectUrl();
        res.redirect(redirectUrl);
    }

    @Get('callback')
    async handleSteamLoginCallback(@Req() req: any): Promise<string> {
        const userData = await this.steamAuthService.authenticate(req);
        console.log(userData);
        return `User login`;
    }
}

Have you any idea to fix this ?

Thank's

p.s: sorry for my english i'm french :-|

tlikakur commented 10 months ago

Hi @Izakun,

Can you try doing import * as SteamAuth from 'node-steam-openid'?

RavMda commented 2 months ago

add "esModuleInterop": true to your tsconfig.json