Angular Django REST Auth Interface
tdn-auth is an Angular module designed to provide an interface for interacting with Django REST Auth backends. As of version 5.0.9, the package primarily targets Angular 5.x. It offers functionalities for authentication flows, including configuration overrides for base URLs and other parameters. The package has not seen updates since its last publish approximately 7 years ago, making it effectively abandoned. It is not compatible with modern Angular versions (Angular 6+) and is best suited for legacy Angular 5 applications. There is no active release cadence or ongoing development. Its key differentiator was providing a pre-built integration layer for a specific Django authentication framework at the time of its release.
Common errors
-
Error: Uncaught (in promise): Error: StaticInjectorError[AuthService]: StaticInjectorError[AuthService]: NullInjectorError: No provider for AuthService!
cause The AuthModule was not properly imported or initialized, specifically `forRoot()` was not called.fixEnsure `AuthModule.forRoot()` is included in the `imports` array of your root Angular module (e.g., `AppModule`). -
Module not found: Error: Can't resolve '@angular/common/http'
cause This package was developed for Angular 5.x, which uses `HttpClientModule` (from `@angular/common/http`) for HTTP requests. Later Angular versions might have subtle changes or require different setup, or you might be missing this specific import.fixEnsure `@angular/common/http` is imported as `HttpClientModule` in your `AppModule` and listed in its `imports` array, alongside `BrowserModule`. -
ERROR in node_modules/tdn-auth/tdn-auth.d.ts(XX,XX): error TS2307: Cannot find module '@angular/core' or its corresponding type declarations.
cause Incompatibility with newer TypeScript versions or mismatched Angular peer dependencies.fixThis package is not compatible with modern Angular versions (6+) or their corresponding TypeScript versions. Revert to Angular 5.x and a compatible TypeScript version (e.g., TypeScript 2.5-2.7) or migrate to a different authentication library.
Warnings
- breaking This package is effectively abandoned and built for Angular 5.x. It will not work with Angular 6+ due to breaking changes in the Angular framework, particularly in RxJS and the Angular CLI's build process, without significant manual intervention and polyfills.
- gotcha The README contains a conflicting import path for `AuthModule` (`angular-auth/auth.module`) versus `AuthConfig` (`tdn-auth/auth.config`). Based on the package name `tdn-auth`, the correct import for `AuthModule` is likely directly from 'tdn-auth'.
- breaking The package has not been updated in approximately 7 years, meaning it likely contains security vulnerabilities due to unpatched dependencies or outdated authentication practices. Using it in production is highly risky.
- gotcha Initialization of `AuthModule` requires `AuthModule.forRoot()` to provide configuration. Simply importing `AuthModule` without calling `forRoot()` will result in missing providers and runtime errors.
Install
-
npm install tdn-auth -
yarn add tdn-auth -
pnpm add tdn-auth
Imports
- AuthModule
import { AuthModule } from 'angular-auth/auth.module';import { AuthModule } from 'tdn-auth'; - AuthConfig
import { AuthConfig } from 'tdn-auth';import { AuthConfig } from 'tdn-auth/auth.config'; - CustomAuthConfig
const CustomAuthConfig = require('tdn-auth/auth.config').AuthConfig; // Incorrect for Angular/TypeScriptimport { Injectable } from '@angular/core'; import { AuthConfig } from 'tdn-auth/auth.config'; @Injectable() export class CustomAuthConfig extends AuthConfig { constructor() { super(); // Customize properties like base_url this.base_url = 'https://your.api.com/auth/'; } }
Quickstart
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AuthModule } from 'tdn-auth';
import { Injectable } from '@angular/core';
import { AuthConfig } from 'tdn-auth/auth.config';
// Assuming you have an Angular environment file for configuration
const environment = {
production: false,
api_base_url: 'https://your-django-rest-auth-api.com/' // Replace with your Django REST Auth API base URL
};
@Injectable()
export class CustomAuthConfig extends AuthConfig {
constructor() {
super();
this.base_url = environment.api_base_url;
// Further customization, e.g., token names, endpoints
// this.login_url = 'auth/jwt/create/';
// this.token_name = 'access_token';
}
}
@NgModule({
imports: [
BrowserModule,
// ... other Angular modules like HttpClientModule for API calls
AuthModule.forRoot(CustomAuthConfig) // Use AuthModule with your custom configuration
],
providers: [],
bootstrap: []
})
export class AppModule { }