feat(login): add Authentik login button and functionality
This commit is contained in:
parent
b218697867
commit
cb658a7721
3 changed files with 53 additions and 6 deletions
|
@ -1,5 +1,10 @@
|
|||
import { Component } from '@angular/core';
|
||||
import { FormControl, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms';
|
||||
import {
|
||||
FormControl,
|
||||
FormGroup,
|
||||
ReactiveFormsModule,
|
||||
Validators,
|
||||
} from '@angular/forms';
|
||||
import PocketBase from 'pocketbase';
|
||||
import { environment } from '../../environments/environment';
|
||||
import { Router } from '@angular/router';
|
||||
|
@ -8,10 +13,19 @@ import { MatFormFieldModule } from '@angular/material/form-field';
|
|||
import { MatInputModule, MatLabel } from '@angular/material/input';
|
||||
import { MatButton, MatButtonModule } from '@angular/material/button';
|
||||
import { MatSnackBar } from '@angular/material/snack-bar';
|
||||
import {MatDividerModule} from '@angular/material/divider';
|
||||
|
||||
@Component({
|
||||
selector: 'app-login',
|
||||
imports: [ReactiveFormsModule, MatCardModule, MatInputModule, MatLabel, MatFormFieldModule, MatButtonModule],
|
||||
imports: [
|
||||
ReactiveFormsModule,
|
||||
MatCardModule,
|
||||
MatInputModule,
|
||||
MatLabel,
|
||||
MatFormFieldModule,
|
||||
MatButtonModule,
|
||||
MatDividerModule,
|
||||
],
|
||||
templateUrl: './login.component.html',
|
||||
styleUrl: './login.component.css',
|
||||
})
|
||||
|
@ -21,7 +35,10 @@ export class LoginComponent {
|
|||
private pb = new PocketBase(environment.POCKETBASE);
|
||||
public errorMessages: Record<string, string> = {};
|
||||
|
||||
constructor(private router: Router, private snackBar: MatSnackBar) { }
|
||||
constructor(
|
||||
private router: Router,
|
||||
private snackBar: MatSnackBar,
|
||||
) { }
|
||||
|
||||
private validationErrorMessages: Record<string, string> = {
|
||||
required: 'This field is required',
|
||||
|
@ -60,6 +77,20 @@ export class LoginComponent {
|
|||
});
|
||||
}
|
||||
|
||||
loginWithAuthentik() {
|
||||
this.pb.collection('users').authWithOAuth2({ provider: 'oidc' })
|
||||
.then(() => {
|
||||
this.router.navigate(['dashboard']);
|
||||
})
|
||||
.catch(() => {
|
||||
this.invalidCredentials = true;
|
||||
const error = this.snackBar.open('Invalid Credentials');
|
||||
setTimeout(() => {
|
||||
error.dismiss();
|
||||
}, 5000);
|
||||
});
|
||||
}
|
||||
|
||||
submit() {
|
||||
if (!this.loginForm.valid) {
|
||||
this.updateErrorMessages();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue