abacritt / angularx-social-login

Social login and authentication module for Angular 17
636 stars 387 forks source link

Support for angular libraries #532

Closed D-Miguel closed 1 year ago

D-Miguel commented 2 years ago

I'm trying to implement this library in an angular library of my own so that I can have multiple different apps implement my own library which can handle the authentication. The reason I'm doing this is because I also have an entire authentication platform I have to support aside from the additional login options such as Facebook and Google.

I'm currently having a problem importing the SocialLoginModule into my library's root module since the SocialLoginModule's constructor checks whether a parentModule already exists (see code fragment), throwing the following error: 'SocialLoginModule is already loaded. Import it in the AppModule only'. I've debugged this part of the code as well and the parentModule that exists in the constructor is an instance of the SocialLoginModule itself.

/**
 * The main module of angularx-social-login library.
 */
class SocialLoginModule {
    constructor(parentModule) {
        if (parentModule) {
            throw new Error('SocialLoginModule is already loaded. Import it in the AppModule only');
        }
    }
    static initialize(config) {
        return {
            ngModule: SocialLoginModule,
            providers: [
                SocialAuthService,
                {
                    provide: 'SocialAuthServiceConfig',
                    useValue: config
                }
            ]
        };
    }
}
SocialLoginModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.3", ngImport: i0, type: SocialLoginModule, deps: [{ token: SocialLoginModule, optional: true, skipSelf: true }], target: i0.ɵɵFactoryTarget.NgModule });
SocialLoginModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.0.3", ngImport: i0, type: SocialLoginModule, declarations: [GoogleSigninButtonDirective], imports: [CommonModule], exports: [GoogleSigninButtonDirective] });

I have found a way to get this library to work with Facebook if I add the 'SocialAuthService' to the providers of my library's root module, but I need to actually import the SocialLoginModule as I want to use the 'GoogleSigninButtonDirective' in my own login component.

The angular version of my library is 14.0.4 and I'm using the latest version of @abacritt/angularx-social-login (1.2.1).

Is there any way to circumvent this issue at the moment or are there any plans to support libraries in the future?

Thanks in advance!

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.