# Replacing/Extending Authentication class in AuthService

**URL:** <https://discourse.aurelia.io/t/replacing-extending-authentication-class-in-authservice/4916>\
**Category:** Uncategorized\
**Created:** [September 14, 2022, 5:48pm UTC](https://discourse.aurelia.io/t/replacing-extending-authentication-class-in-authservice/4916 "2022-09-14T17:48:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![TomorrowToday](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/tomorrowtoday/32/2343_2.png) [@TomorrowToday](https://discourse.aurelia.io/u/TomorrowToday)\
**Post date:** [September 14, 2022, 5:48pm UTC](https://discourse.aurelia.io/t/replacing-extending-authentication-class-in-authservice/4916/1 "2022-09-14T17:48:38Z")

</div>

I have a project using aurelia-auth plugin. I would like to extend parts of the Authentication class so it can handle a more complex flow. All of my attempts to tell the DI system to use the CustomAuth class in its place are failing though. In particular, it seems Container.instance.registerSingleton doesn’t work how I expect from what the docs say:

myauth.js

```auto
import {Container, inject} from 'aurelia-framework';
import {Authentication} from 'aurelia-auth';

export class CustomAuth extends Authentication {
    constructor(...rest){
        super(...rest)
        console.log('CustomAuth created')
    }
}
Container.instance.registerSingleton(Authentication, CustomAuth);

export class CustomAuthService extends AuthService {
    constructor(...rest){
        super(...rest)
    }
}

```

app.js

```auto
import {inject} from 'aurelia-framework';
import {AuthorizeStep, FetchConfig} from 'aurelia-auth';
import {CustomAuthService} from './myauth';

inject(CustomAuthService, FetchConfig);
export class App {
    constructor(auth, fetchConfig){
        this.auth = auth
        this.fetchConfig = fetchConfig
    }
    activate() {
         this.fetchConfig.configure();
    }
    configureRouter(config, router) {
        config.addPipelineStep('authorize', AuthorizeStep);
    }
    //...
}

```

error I’m getting:  
`Error: key/value cannot be null or undefined. Are you trying to inject/register something that doesn't exist with DI?`

Why does it thinks the key or value is missing?

---

<div class="post-metadata">

**Author:** ![TomorrowToday](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/tomorrowtoday/32/2343_2.png) [@TomorrowToday](https://discourse.aurelia.io/u/TomorrowToday)\
**Post date:** [September 14, 2022, 7:31pm UTC](https://discourse.aurelia.io/t/replacing-extending-authentication-class-in-authservice/4916/2 "2022-09-14T19:31:25Z")

</div>

hmmm… so it seems that the registerSingleton method takes a function or Instance as the second argument not the class. Is there a way to do what I want with a Resolver?

---

<div class="post-metadata">

**Author:** ![TomorrowToday](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/tomorrowtoday/32/2343_2.png) [@TomorrowToday](https://discourse.aurelia.io/u/TomorrowToday)\
**Post date:** [September 14, 2022, 10:23pm UTC](https://discourse.aurelia.io/t/replacing-extending-authentication-class-in-authservice/4916/3 "2022-09-14T22:23:38Z")

</div>

Something even more fundamental is going on and I’m not seeing what. Can’t event extend from the classes in aurelia-auth with out errors for getting prototype of undefined.

Ultimately I just trying to get it to work with Firebase Authentication so I don’t have to rewrite a lot of code that uses AuthService and events published by it.

Has anyone else out there tried to extend aurelia-auth or figured out how to shoe-horn firebase/auth into it?

---

<div class="post-metadata">

**Author:** ![elitastic](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/elitastic/32/1787_2.png) [@elitastic](https://discourse.aurelia.io/u/elitastic)\
**Post date:** [September 15, 2022, 5:27am UTC](https://discourse.aurelia.io/t/replacing-extending-authentication-class-in-authservice/4916/4 "2022-09-15T05:27:37Z")

</div>

> [@TomorrowToday](#):
>
> ```auto
> Container.instance.registerSingleton(Authentication, CustomAuth);
> 
> ```

This looks correct, but shouldn’t you do the same for your CustomAuthService, like:

```auto
Container.instance.registerSingleton(CustomAuthService);

```

---

<div class="post-metadata">

**Author:** ![TomorrowToday](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/tomorrowtoday/32/2343_2.png) [@TomorrowToday](https://discourse.aurelia.io/u/TomorrowToday)\
**Post date:** [September 15, 2022, 2:28pm UTC](https://discourse.aurelia.io/t/replacing-extending-authentication-class-in-authservice/4916/5 "2022-09-15T14:28:20Z")

</div>

Maybe? Don’t know because aurelia-auth doesn’t work with extend for some reason. Think I’ll just fork the project to make my changes. If I need to extend another plugin’s classes I’ll give the Container api another try.
