Search code examples
angularweb-applicationsreset-passwordexternal-links

Angular component not found from external link in reset password feature


newbie here. I'm trying to code a reset password feature for a java Spring Boot app. The front works with Angular 7.

The user enters his email and clicks on a reset button. Then, a token is stored in the user table and the user receives a mail with a link like this one :

http://localhost:4200/reset-password?token=7f278bf1-40c7-4b1a-bde5-76744b866241

When I click on this link, I have a 404 error. The app doesn't seem to find the ResetPasswordForm component.

reset-password-form.module.ts :

import { ResetPasswordFormComponent } from './reset-password-form.component';
import { Routes, RouterModule } from '@angular/router';
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { MaterialModule } from '../material/material.module';
import { ClassementModule } from '../classement/classement.module';
import { HttpClientModule } from '@angular/common/http';

const routes: Routes = [
    { path: 'reset-password', component: ResetPasswordFormComponent }
    // { path: '', component: HomeComponent }
  ];

  @NgModule({
    declarations: [ResetPasswordFormComponent],
    imports: [
      CommonModule,
      MaterialModule,
      ClassementModule,
      HttpClientModule,
      RouterModule.forChild(routes)
    ]
  })
  export class ResetPasswordModule { }

app-routing.module.ts :

...
import { ResetPasswordFormComponent } from './site/reset-password-form/reset-password-form.component';
...
{ path: 'reset-password', component: ResetPasswordFormComponent}
...
@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule { }

app.module.ts

...
import { ResetPasswordModule } from './site/reset-password-form/reset-password-form.module';
...
@NgModule({
  declarations: [
    AppComponent,
    ConfirmDialogComponent,
    UserComponent,
    AlertComponent,
  ],
  imports: [
    ...
    ResetPasswordModule
  ],
  providers: [httpInterceptorProviders, {provide: LOCALE_ID, useValue: "fr-FR", }, DatePipe],
  entryComponents: [ConfirmDialogComponent, AlertComponent],
  bootstrap: [AppComponent]
})

export class AppModule { }

reset-password-form.component.ts

import { Component, OnInit } from '@angular/core';
import { AuthService } from '../auth/auth.service';

@Component({
  selector: 'app-reset-password-form',
  templateUrl: './reset-password-form.component.html',
  styleUrls: ['./reset-password-form.component.scss']
})
export class ResetPasswordFormComponent implements OnInit {

  constructor(private authService: AuthService) { }

  ngOnInit() {
    if(this.authService.isLoggedIn) {
      console.log("logged in")
    }
    else {
      console.log("not logged in")
    }
  }

}

It's been days I'm on this feature and well I'm quite tired, I think I made something wrong. Could you help me?


Solution

  • I just erased all and did it again from scratch and now it works. Don't know what I forgot...