diff --git a/frontend/package-lock.json b/frontend/package-lock.json index d976233..45c6dd8 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -23,8 +23,6 @@ "apollo-angular": "^8.0.0", "express": "^4.21.2", "graphql": "^16.9.0", - "keycloak-angular": "^16.1.0", - "keycloak-js": "^26.0.7", "rxjs": "~7.8.0", "tslib": "^2.3.0", "zone.js": "~0.14.10" @@ -9095,27 +9093,6 @@ "node": ">=10" } }, - "node_modules/keycloak-angular": { - "version": "16.1.0", - "resolved": "https://registry.npmjs.org/keycloak-angular/-/keycloak-angular-16.1.0.tgz", - "integrity": "sha512-y2Eow2mISE0tY+ZOGzgiDISJ69faInYyV1ONwv+8mzU9Rn0xMPEjw7rQCRm9XsyFZiqM0LLucx9m73FCnl4wAg==", - "license": "MIT", - "dependencies": { - "tslib": "^2.3.1" - }, - "peerDependencies": { - "@angular/common": "^18", - "@angular/core": "^18", - "@angular/router": "^18", - "keycloak-js": "^18 || ^19 || ^20 || ^21 || ^22 || ^23 || ^24 || ^25 || ^26" - } - }, - "node_modules/keycloak-js": { - "version": "26.0.7", - "resolved": "https://registry.npmjs.org/keycloak-js/-/keycloak-js-26.0.7.tgz", - "integrity": "sha512-vKCk1ISMiouYRLjMzi5fKp58RnYxKEBS29BoDgVfYwVW94IXchj9jLqBvIet31VD1v79l3WaWT+WMX7fH8O4wA==", - "license": "Apache-2.0" - }, "node_modules/kind-of": { "version": "6.0.3", "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.3.tgz", diff --git a/frontend/package.json b/frontend/package.json index f37293e..f29b02c 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -27,8 +27,6 @@ "apollo-angular": "^8.0.0", "express": "^4.21.2", "graphql": "^16.9.0", - "keycloak-angular": "^16.1.0", - "keycloak-js": "^26.0.7", "rxjs": "~7.8.0", "tslib": "^2.3.0", "zone.js": "~0.14.10" diff --git a/frontend/src/app/app.component.html b/frontend/src/app/app.component.html index 1c4976f..45bebd5 100644 --- a/frontend/src/app/app.component.html +++ b/frontend/src/app/app.component.html @@ -1,5 +1,5 @@ -
- - -
+ + + + diff --git a/frontend/src/app/app.config.ts b/frontend/src/app/app.config.ts index 49d6cb7..1584f98 100644 --- a/frontend/src/app/app.config.ts +++ b/frontend/src/app/app.config.ts @@ -7,9 +7,8 @@ import {HTTP_INTERCEPTORS, provideHttpClient} from '@angular/common/http'; import { provideApollo } from 'apollo-angular'; import { HttpLink } from 'apollo-angular/http'; import { InMemoryCache } from '@apollo/client/core'; -import { KeycloakService } from 'keycloak-angular'; -import {initKeycloak} from "./init-keycloak"; import {AuthInterceptor} from "./core/services/auth-interceptor.service"; +import {environment} from "../environments/environment"; export const appConfig: ApplicationConfig = { providers: [ @@ -22,18 +21,11 @@ export const appConfig: ApplicationConfig = { return { link: httpLink.create({ - uri: '<%= endpoint %>', + uri: environment.auth_service, }), cache: new InMemoryCache(), }; }), - KeycloakService, - { - provide: APP_INITIALIZER, - useFactory: initKeycloak, - deps: [KeycloakService], - multi: true - }, { provide: HTTP_INTERCEPTORS, useClass: AuthInterceptor, diff --git a/frontend/src/app/app.routes.ts b/frontend/src/app/app.routes.ts index 92b4ebc..459114a 100644 --- a/frontend/src/app/app.routes.ts +++ b/frontend/src/app/app.routes.ts @@ -1,8 +1,13 @@ import { Routes } from '@angular/router'; -import {AuthGuard} from "./core/services/auth-guard.service"; import {AppComponent} from "./app.component"; +import {LoginComponent} from "./features/auth/componets/login/login.component"; +import {RegisterComponent} from "./features/auth/componets/register/register.component"; +import {ProfileComponent} from "./features/auth/componets/profile/profile.component"; export const routes: Routes = [ // { path: '', component: AppComponent, canActivate: [AuthGuard] }, + { path: 'sentemon', component: ProfileComponent }, + { path: 'login', component: LoginComponent }, + { path: 'register', component: RegisterComponent }, { path: '**', redirectTo: '', pathMatch: 'full' } ]; diff --git a/frontend/src/app/core/services/auth-guard.service.ts b/frontend/src/app/core/services/auth-guard.service.ts index b336944..8a8fa64 100644 --- a/frontend/src/app/core/services/auth-guard.service.ts +++ b/frontend/src/app/core/services/auth-guard.service.ts @@ -1,31 +1,9 @@ -import { Injectable, Inject, PLATFORM_ID } from '@angular/core'; -import { KeycloakAuthGuard, KeycloakService } from "keycloak-angular"; -import { ActivatedRouteSnapshot, Router, RouterStateSnapshot } from "@angular/router"; +import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root' }) -export class AuthGuard extends KeycloakAuthGuard { +export class AuthGuard { - constructor( - protected override router: Router, - protected override keycloakAngular: KeycloakService, - @Inject(PLATFORM_ID) private platformId: Object - ) { - super(router, keycloakAngular); - } - - public override async isAccessAllowed( - route: ActivatedRouteSnapshot, - state: RouterStateSnapshot): Promise { - if (!this.keycloakAngular.isLoggedIn()) { - await this.keycloakAngular.login({ - redirectUri: window.location.origin + state.url - }); - - return false; - } - - return true; - } + constructor() {} } diff --git a/frontend/src/app/core/services/auth-interceptor.service.ts b/frontend/src/app/core/services/auth-interceptor.service.ts index 162d52f..06fb771 100644 --- a/frontend/src/app/core/services/auth-interceptor.service.ts +++ b/frontend/src/app/core/services/auth-interceptor.service.ts @@ -1,38 +1,16 @@ import { Injectable } from '@angular/core'; import {HttpEvent, HttpHandler, HttpInterceptor, HttpRequest} from "@angular/common/http"; import {Observable} from 'rxjs'; -import {KeycloakService} from "keycloak-angular"; @Injectable({ providedIn: 'root' }) export class AuthInterceptor implements HttpInterceptor { - constructor(private keycloakService: KeycloakService) { } + constructor() { } intercept(req: HttpRequest, next: HttpHandler): Observable> { - return new Observable(observer => { - this.keycloakService.updateToken(5).then(() => { - const token = this.keycloakService.getKeycloakInstance().token; - - if (token) { - req = req.clone({ - setHeaders: { - Authorization: `Bearer ${token}`, - }, - }); - } - - next.handle(req).subscribe( - event => observer.next(event), - err => observer.error(err), - () => observer.complete() - ); - }).catch(err => { - console.error('Failed to refresh token', err); - observer.error(err); - }); - }); + return new Observable() } } diff --git a/frontend/src/app/features/auth/componets/auth.scss b/frontend/src/app/features/auth/componets/auth.scss new file mode 100644 index 0000000..aee4d17 --- /dev/null +++ b/frontend/src/app/features/auth/componets/auth.scss @@ -0,0 +1,59 @@ +.form { + display: flex; + justify-content: center; + align-items: center; + height: 100vh; + + form { + display: flex; + flex-direction: column; + + h1 { + margin-bottom: 1.5rem; + text-align: center; + } + + .fields { + display: flex; + flex-direction: column; + gap: 1rem; + + input { + padding: 0.8rem; + font-size: 1rem; + border: 1px solid #ccc; + border-radius: 4px; + outline: none; + transition: border-color 0.3s; + + &:focus { + border-color: #007bff; + } + } + } + + button { + margin-top: 1rem; + padding: 0.8rem; + font-size: 1rem; + color: white; + background-color: black; + border: none; + border-radius: 4px; + cursor: pointer; + transition: background-color 0.3s; + + &:hover { + background-color: #333; + } + } + + p { + margin-top: 10px; + + a { + text-decoration: none; + } + } + } +} diff --git a/frontend/src/app/features/auth/componets/login/login.component.html b/frontend/src/app/features/auth/componets/login/login.component.html new file mode 100644 index 0000000..ba33bde --- /dev/null +++ b/frontend/src/app/features/auth/componets/login/login.component.html @@ -0,0 +1,11 @@ +
+
+

Login to Fitness App

+
+ + +
+ +

Don't have an account? Register

+
+
diff --git a/frontend/src/app/features/auth/componets/login/login.component.spec.ts b/frontend/src/app/features/auth/componets/login/login.component.spec.ts new file mode 100644 index 0000000..18f3685 --- /dev/null +++ b/frontend/src/app/features/auth/componets/login/login.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { LoginComponent } from './login.component'; + +describe('LoginComponent', () => { + let component: LoginComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [LoginComponent] + }) + .compileComponents(); + + fixture = TestBed.createComponent(LoginComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/frontend/src/app/features/auth/componets/login/login.component.ts b/frontend/src/app/features/auth/componets/login/login.component.ts new file mode 100644 index 0000000..98a9fed --- /dev/null +++ b/frontend/src/app/features/auth/componets/login/login.component.ts @@ -0,0 +1,38 @@ +import { Component } from '@angular/core'; +import {FormBuilder, FormGroup, ReactiveFormsModule, Validators} from "@angular/forms"; +import {NgIf} from "@angular/common"; +import {RouterLink} from "@angular/router"; +import {AuthGuardService} from "../../services/auth-guard.service"; + +@Component({ + selector: 'app-login', + standalone: true, + imports: [ + ReactiveFormsModule, + NgIf, + RouterLink + ], + templateUrl: './login.component.html', + styleUrl: './../auth.scss' +}) +export class LoginComponent { + loginForm: FormGroup; + + constructor(private authGuardService: AuthGuardService, private formBuilder: FormBuilder) { + this.loginForm = this.formBuilder.group({ + email: ['', [Validators.required]], + password: ['', [Validators.required, Validators.minLength(6)]] + }) + } + onLogin() { + if (this.loginForm.valid) { + // ToDo: save to cookie + this.authGuardService.login(this.loginForm.value.email, this.loginForm.value.password).subscribe(result => { + console.log(result); + }); + } else { + // ToDo + console.log('Form is invalid', this.loginForm.errors); + } + } +} diff --git a/frontend/src/app/features/auth/componets/logout/logout.component.html b/frontend/src/app/features/auth/componets/logout/logout.component.html new file mode 100644 index 0000000..c6ae40e --- /dev/null +++ b/frontend/src/app/features/auth/componets/logout/logout.component.html @@ -0,0 +1 @@ +

logout works!

diff --git a/frontend/src/app/features/auth/componets/logout/logout.component.scss b/frontend/src/app/features/auth/componets/logout/logout.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/frontend/src/app/features/auth/componets/logout/logout.component.spec.ts b/frontend/src/app/features/auth/componets/logout/logout.component.spec.ts new file mode 100644 index 0000000..a0f3fbe --- /dev/null +++ b/frontend/src/app/features/auth/componets/logout/logout.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { LogoutComponent } from './logout.component'; + +describe('LogoutComponent', () => { + let component: LogoutComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [LogoutComponent] + }) + .compileComponents(); + + fixture = TestBed.createComponent(LogoutComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/frontend/src/app/features/auth/componets/logout/logout.component.ts b/frontend/src/app/features/auth/componets/logout/logout.component.ts new file mode 100644 index 0000000..0613572 --- /dev/null +++ b/frontend/src/app/features/auth/componets/logout/logout.component.ts @@ -0,0 +1,12 @@ +import { Component } from '@angular/core'; + +@Component({ + selector: 'app-logout', + standalone: true, + imports: [], + templateUrl: './logout.component.html', + styleUrl: './logout.component.scss' +}) +export class LogoutComponent { + +} diff --git a/frontend/src/app/features/auth/componets/profile/profile.component.html b/frontend/src/app/features/auth/componets/profile/profile.component.html new file mode 100644 index 0000000..4cf112c --- /dev/null +++ b/frontend/src/app/features/auth/componets/profile/profile.component.html @@ -0,0 +1,5 @@ +

profile works!

+

{{ user?.firstName }}

+

{{ user?.lastName }}

+

{{ user?.username }}

+ diff --git a/frontend/src/app/features/auth/componets/profile/profile.component.scss b/frontend/src/app/features/auth/componets/profile/profile.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/frontend/src/app/features/auth/componets/profile/profile.component.spec.ts b/frontend/src/app/features/auth/componets/profile/profile.component.spec.ts new file mode 100644 index 0000000..17789ee --- /dev/null +++ b/frontend/src/app/features/auth/componets/profile/profile.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { ProfileComponent } from './profile.component'; + +describe('ProfileComponent', () => { + let component: ProfileComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [ProfileComponent] + }) + .compileComponents(); + + fixture = TestBed.createComponent(ProfileComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/frontend/src/app/features/auth/componets/profile/profile.component.ts b/frontend/src/app/features/auth/componets/profile/profile.component.ts new file mode 100644 index 0000000..8a3c393 --- /dev/null +++ b/frontend/src/app/features/auth/componets/profile/profile.component.ts @@ -0,0 +1,24 @@ +import {Component } from '@angular/core'; +import {UserService} from "../../services/user.service"; +import {User} from "../../models/user.model"; + +@Component({ + selector: 'app-profile', + standalone: true, + imports: [], + templateUrl: './profile.component.html', + styleUrl: './profile.component.scss' +}) +export class ProfileComponent { + user?: User; + + constructor(private userService: UserService) { } + + getSentemon(): void { + this.userService.getUserByUsername("sentemon").subscribe(result => { + this.user = result; + }); + console.log(this.user); + } + +} diff --git a/frontend/src/app/features/auth/componets/register/register.component.html b/frontend/src/app/features/auth/componets/register/register.component.html new file mode 100644 index 0000000..b5740ea --- /dev/null +++ b/frontend/src/app/features/auth/componets/register/register.component.html @@ -0,0 +1,15 @@ +
+
+

Register to Fitness App

+
+ + + + + + +
+ +

Already have an account? Login

+
+
diff --git a/frontend/src/app/features/auth/componets/register/register.component.spec.ts b/frontend/src/app/features/auth/componets/register/register.component.spec.ts new file mode 100644 index 0000000..757b895 --- /dev/null +++ b/frontend/src/app/features/auth/componets/register/register.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { RegisterComponent } from './register.component'; + +describe('RegisterComponent', () => { + let component: RegisterComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [RegisterComponent] + }) + .compileComponents(); + + fixture = TestBed.createComponent(RegisterComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/frontend/src/app/features/auth/componets/register/register.component.ts b/frontend/src/app/features/auth/componets/register/register.component.ts new file mode 100644 index 0000000..fad2045 --- /dev/null +++ b/frontend/src/app/features/auth/componets/register/register.component.ts @@ -0,0 +1,60 @@ +import { Component } from '@angular/core'; +import { + AbstractControl, + FormBuilder, + FormGroup, + ReactiveFormsModule, + ValidationErrors, + Validators +} from "@angular/forms"; +import {RouterLink} from "@angular/router"; +import {AuthGuardService} from "../../services/auth-guard.service"; + +@Component({ + selector: 'app-register', + standalone: true, + imports: [ + ReactiveFormsModule, + RouterLink + ], + templateUrl: './register.component.html', + styleUrl: './../auth.scss' +}) +export class RegisterComponent { + registerForm: FormGroup; + + constructor(private authGuardService: AuthGuardService, private formBuilder: FormBuilder) { + this.registerForm = this.formBuilder.group({ + firstName: ['', [Validators.required]], + lastName: ['', [Validators.required]], + username: ['', [Validators.required]], // ToDo: regex check + email: ['', [Validators.required, Validators.email]], + password: ['', [Validators.required, Validators.minLength(6)]], + confirmPassword: ['', [Validators.required]], + }, { validators: this.passwordMatchValidator }) + } + + onRegister() { + if (this.registerForm.valid) { + // ToDo: save to cookie + this.authGuardService.register( + this.registerForm.value.firstName, + this.registerForm.value.lastName, + this.registerForm.value.username, + this.registerForm.value.email, + this.registerForm.value.password + ).subscribe(result => { + console.log(result); + }); + } else { + // ToDo + console.log('Form is invalid', this.registerForm.errors); + } + } + + private passwordMatchValidator(group: AbstractControl): ValidationErrors | null { + const password = group.get('password')?.value; + const confirmPassword = group.get('confirmPassword')?.value; + return password === confirmPassword ? null : { passwordMismatch: true }; + } +} diff --git a/frontend/src/app/features/auth/models/token.model.ts b/frontend/src/app/features/auth/models/token.model.ts new file mode 100644 index 0000000..60d56e6 --- /dev/null +++ b/frontend/src/app/features/auth/models/token.model.ts @@ -0,0 +1,10 @@ +export interface Token { + accessToken: string + expiresIn: number + refreshExpiresIn: number + refreshToken: string + tokenType: string + notBeforePolicy: number + sessionState: string + scope: string +} diff --git a/frontend/src/app/features/auth/models/user.model.ts b/frontend/src/app/features/auth/models/user.model.ts new file mode 100644 index 0000000..f2be6fc --- /dev/null +++ b/frontend/src/app/features/auth/models/user.model.ts @@ -0,0 +1,7 @@ +export interface User { + firstName: string; + lastName: string; + username: string; + email: string; + imageUrl: string; +} diff --git a/frontend/src/app/features/auth/requests/mutations.ts b/frontend/src/app/features/auth/requests/mutations.ts new file mode 100644 index 0000000..e3be16b --- /dev/null +++ b/frontend/src/app/features/auth/requests/mutations.ts @@ -0,0 +1,37 @@ +import gql from 'graphql-tag'; + +export const LOGIN = gql` + mutation Login($username: String!, $password: String!) { + login(input: { username: $username, password: $password }) { + accessToken + expiresIn + refreshExpiresIn + refreshToken + tokenType + notBeforePolicy + sessionState + scope + } + } +`; + +export const REGISTER = gql` + mutation Register($firstName: String!, $lastName: String!, $username: String!, $email: String!, $password: String!) { + register(input: { + firstName: $firstName, + lastName: $lastName, + username: $username, + email: $email, + password: $password + }) { + accessToken + expiresIn + refreshExpiresIn + refreshToken + tokenType + notBeforePolicy + sessionState + scope + } + } +`; diff --git a/frontend/src/app/features/auth/requests/queries.ts b/frontend/src/app/features/auth/requests/queries.ts new file mode 100644 index 0000000..fc06b7c --- /dev/null +++ b/frontend/src/app/features/auth/requests/queries.ts @@ -0,0 +1,13 @@ +import gql from 'graphql-tag'; + +export const GET_USER_BY_USERNAME = gql` + query UserByUsername($username: String!) { + userByUsername(username: $username) { + firstName + lastName + username + email + imageUrl + } + } +`; diff --git a/frontend/src/app/features/auth/responses/token.response.ts b/frontend/src/app/features/auth/responses/token.response.ts new file mode 100644 index 0000000..5768336 --- /dev/null +++ b/frontend/src/app/features/auth/responses/token.response.ts @@ -0,0 +1,6 @@ +import {Token} from "../models/token.model"; + +export interface TokenResponse { + login: Token + register: Token +} diff --git a/frontend/src/app/features/auth/responses/user.response.ts b/frontend/src/app/features/auth/responses/user.response.ts new file mode 100644 index 0000000..dc55c7d --- /dev/null +++ b/frontend/src/app/features/auth/responses/user.response.ts @@ -0,0 +1,5 @@ +import {User} from "../models/user.model"; + +export interface UserResponse { + userByUsername: User; +} diff --git a/frontend/src/app/features/auth/services/auth-guard.service.spec.ts b/frontend/src/app/features/auth/services/auth-guard.service.spec.ts new file mode 100644 index 0000000..35afd37 --- /dev/null +++ b/frontend/src/app/features/auth/services/auth-guard.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { AuthGuardService } from './auth-guard.service'; + +describe('AuthGuardService', () => { + let service: AuthGuardService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(AuthGuardService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/frontend/src/app/features/auth/services/auth-guard.service.ts b/frontend/src/app/features/auth/services/auth-guard.service.ts new file mode 100644 index 0000000..593b0a0 --- /dev/null +++ b/frontend/src/app/features/auth/services/auth-guard.service.ts @@ -0,0 +1,32 @@ +import { Injectable } from '@angular/core'; +import {Apollo} from "apollo-angular"; +import {map, Observable} from "rxjs"; +import {LOGIN, REGISTER} from "../requests/mutations"; +import {Token} from "../models/token.model"; +import {TokenResponse} from "../responses/token.response"; + +@Injectable({ + providedIn: 'root' +}) +export class AuthGuardService { + + constructor(private apollo: Apollo) { } + + public login(username: string, password: string) : Observable { + return this.apollo.mutate({ + mutation: LOGIN, + variables: { username, password } + }).pipe( + map(response => response.data?.login) + ); + } + + public register(firstName: string, lastName: string, username: string, email: string, password: string) : Observable { + return this.apollo.mutate({ + mutation: REGISTER, + variables: { firstName, lastName, username, email, password } + }).pipe( + map(response => response.data?.register) + ); + } +} diff --git a/frontend/src/app/features/auth/services/user.service.spec.ts b/frontend/src/app/features/auth/services/user.service.spec.ts new file mode 100644 index 0000000..3f804c9 --- /dev/null +++ b/frontend/src/app/features/auth/services/user.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { UserService } from './user.service'; + +describe('UserService', () => { + let service: UserService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(UserService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/frontend/src/app/features/auth/services/user.service.ts b/frontend/src/app/features/auth/services/user.service.ts new file mode 100644 index 0000000..4bae73a --- /dev/null +++ b/frontend/src/app/features/auth/services/user.service.ts @@ -0,0 +1,23 @@ +import { Injectable } from '@angular/core'; +import {Apollo} from "apollo-angular"; +import {map, Observable} from "rxjs"; +import {GET_USER_BY_USERNAME} from "../requests/queries"; +import {User} from "../models/user.model"; +import {UserResponse} from "../responses/user.response"; + +@Injectable({ + providedIn: 'root' +}) +export class UserService { + + constructor(private apollo: Apollo) { } + + getUserByUsername(username: string): Observable { + return this.apollo.query({ + query: GET_USER_BY_USERNAME, + variables: { username } + }).pipe( + map(response => response.data.userByUsername) + ); + } +} diff --git a/frontend/src/app/init-keycloak.ts b/frontend/src/app/init-keycloak.ts deleted file mode 100644 index b3eddd4..0000000 --- a/frontend/src/app/init-keycloak.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { KeycloakService } from 'keycloak-angular'; -import { environment } from "../environments/environment"; - -const Keycloak = typeof window !== 'undefined' ? import('keycloak-js') : null; - -export function initKeycloak(keycloak: KeycloakService) { - if (Keycloak !== null) { - return () => - keycloak.init({ - config: { - url: environment.keycloak.url, - realm: environment.keycloak.realm, - clientId: environment.keycloak.clientId, - }, - initOptions: { - onLoad: 'check-sso', - silentCheckSsoRedirectUri: window.location.origin + '/assets/silent-check-sso.html', - }, - enableBearerInterceptor: true, - bearerPrefix: 'Bearer', - }); - } - - return () => { - return new Promise((resolve) => { - resolve(true); - }); - }; -} diff --git a/frontend/src/environments/environment.ts b/frontend/src/environments/environment.ts index 3595100..da2fa86 100644 --- a/frontend/src/environments/environment.ts +++ b/frontend/src/environments/environment.ts @@ -1,8 +1,4 @@ export const environment = { - production: false, - keycloak: { - url: 'http://localhost:8080/', - realm: 'fitness-app-realm', - clientId: 'fitness-app-client', - }, + auth_service: "http://localhost:8082/graphql", + production: false };