I need to create an (invisible) landing page that just gets some data from the URL query parameters and then shoves that into the Route state when navigating to a new view. My linter is complaining about using an async method with effect, but it does work. Any suggestions for how to do this in a better way?
export class ActionsComponent {
public readonly continueUrl = input<string>();
public readonly lang = input<string>();
public readonly mode = input<string>();
public readonly oobCode = input<string>();
private readonly _actionState: Signal<Partial<ActionCodeState>>;
private readonly _modePaths: Record<string, string>;
private readonly _router: Router;
constructor() {
this._actionState = computed(() => ({
continueUrl: this.continueUrl(),
lang: this.lang(),
mode: this.mode(),
oobCode: this.oobCode(),
}));
this._modePaths = {
recoverEmail: '/recover-email',
resetPassword: '/reset-password',
verifyEmail: '/verify-email',
};
this._router = inject(Router);
// eslint-disable-next-line @typescript-eslint/no-misused-promises -- This works, for now, but perhaps not in the future!
effect(async (): Promise<void> => {
const state = this._actionState();
if (state.mode && state.oobCode) {
const path = this._modePaths[state.mode];
if (path) {
await this._router.navigateByUrl(path, { replaceUrl: true, state });
} else {
console.error(`Unknown mode '${state.mode}'`);
}
} else {
if (!state.mode) {
console.error('Missing ActionCodeSettings#mode');
}
if (!state.oobCode) {
console.error('Missing ActionCodeSettings#oobCode');
}
}
// Something about this action is invalid.
// Navigate to root to allow default redirectTo Route to decide initial destination.
await this._router.navigateByUrl('/', { replaceUrl: true });
});
}
}