{ "version": 3, "sources": ["src/app/modules/auth/auth.service.ts", "src/app/services/user-profile.service.ts"], "sourcesContent": ["import { Inject, Injectable, PLATFORM_ID } from '@angular/core';\r\nimport { isPlatformBrowser } from '@angular/common';\r\nimport { HttpClient } from '@angular/common/http';\r\nimport { Observable, Subject } from 'rxjs';\r\nimport { baseURL } from '@env';\r\n\r\nimport { SocialAuthService, SocialUser } from \"@abacritt/angularx-social-login\";\r\nimport { ExternalAccessToken, ExternalLoginResponse, ExternalAuth, IAuth, IRegistration, RegisterValidate } from '@interfaces/auth.interfaces';\r\n\r\n\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class AuthService {\r\n private extAuthChangeSub = new Subject();\r\n public extAuthChanged = this.extAuthChangeSub.asObservable();\r\n\r\n private isBrowser: boolean = true;\r\n\r\n constructor(\r\n @Inject(PLATFORM_ID) private _platformId: Object,\r\n private http: HttpClient,\r\n private externalAuthService: SocialAuthService,\r\n ) {\r\n this.externalAuthService.authState.subscribe((user: SocialUser) => {\r\n this.extAuthChangeSub.next(user);\r\n });\r\n\r\n this.isBrowser = isPlatformBrowser(this._platformId);\r\n }\r\n\r\n registration!: IRegistration | undefined;\r\n\r\n setRegistration(registration: IRegistration): void {\r\n this.registration = registration;\r\n }\r\n\r\n getRegistration(): IRegistration {\r\n return this.registration!;\r\n }\r\n\r\n saveExpiry(): void {\r\n if (this.isBrowser) {\r\n const expiry = +new Date() + 604800000;\r\n \r\n localStorage.removeItem('auth-user-expire');\r\n localStorage.setItem('auth-user-expire', JSON.stringify(expiry));\r\n }\r\n }\r\n\r\n authenticate(auth: IAuth): Observable {\r\n return this.http.post(`${baseURL}user/login`, auth);\r\n }\r\n\r\n registrate(registration: IRegistration): Observable {\r\n return this.http.post(`${baseURL}user/register`, registration);\r\n }\r\n\r\n passwordRecovery(pass: string): Observable {\r\n return this.http.post(`${baseURL}user/forgot-password`, pass);\r\n }\r\n\r\n requestRegistration(wizards: IRegistration) {\r\n this.registration = { ...this.registration, ...wizards };\r\n return this.registrate(this.registration);\r\n }\r\n\r\n validateRegister(register: RegisterValidate): Observable {\r\n return this.http.post(`${baseURL}user/validate-register`, register);\r\n }\r\n\r\n logOut(): Observable {\r\n return this.http.post(`${baseURL}user/logout`, null);\r\n }\r\n\r\n resetPassword(pass: { [key: string]: string }): Observable {\r\n return this.http.post(`${baseURL}user/reset-password`, pass);\r\n }\r\n\r\n validateToken(pass: { [key: string]: string }): Observable {\r\n return this.http.post(`${baseURL}user/validate-reset-token`, pass);\r\n }\r\n\r\n\r\n // External auth\r\n\r\n externalRegister(userData: ExternalAuth): Observable {\r\n return this.http.post(`${baseURL}user/external-register`, userData);\r\n }\r\n\r\n externalLogin(accessToken: ExternalAccessToken, provider: string): Observable {\r\n return this.http.post(`${baseURL}user/login-${provider}`, accessToken);\r\n }\r\n\r\n externalLink(accessToken: ExternalAccessToken, provider: string): Observable {\r\n return this.http.post(`${baseURL}user/link-${provider}`, accessToken);\r\n }\r\n\r\n externalUnlink(provider: string): Observable {\r\n return this.http.delete(`${baseURL}user/unlink-${provider}`);\r\n }\r\n\r\n signInExternal(provider: string): Promise {\r\n return this.externalAuthService.signIn(provider);\r\n }\r\n\r\n signOutExternal(): void {\r\n this.externalAuthService.signOut();\r\n }\r\n}\r\n", "import { HttpClient } from '@angular/common/http';\r\nimport { isPlatformBrowser } from '@angular/common';\r\nimport { Inject, Injectable, PLATFORM_ID } from '@angular/core';\r\nimport { BehaviorSubject, Observable } from 'rxjs';\r\n\r\nimport { baseURL } from '@env';\r\nimport { ChangePassword, UserProfile, UserProfileUpdate } from '@interfaces/user-profile.interfaces';\r\nimport { AlertType } from '@shared/alert/interfaces/alert.enum';\r\n\r\nconst AUTH_EXP = 'auth-user-expire';\r\n\r\n@Injectable({\r\n providedIn: 'root'\r\n})\r\nexport class UserProfileService {\r\n alertTypes = AlertType;\r\n private isBrowser: boolean = true;\r\n\r\n private userSub = new BehaviorSubject(null!);\r\n user$ = this.userSub.asObservable();\r\n\r\n constructor(\r\n @Inject(PLATFORM_ID) private _platformId: Object,\r\n private http: HttpClient,\r\n ) {\r\n this.isBrowser = isPlatformBrowser(this._platformId);\r\n }\r\n\r\n clearUser(): void {\r\n if (this.isBrowser) {\r\n localStorage.removeItem(AUTH_EXP);\r\n this.setUser(null!);\r\n }\r\n }\r\n\r\n setUser(user: UserProfile): void {\r\n this.userSub.next(user);\r\n }\r\n\r\n isLoggedIn(): boolean {\r\n if (!this.isBrowser) {\r\n return false;\r\n }\r\n \r\n const expiry = localStorage.getItem(AUTH_EXP);\r\n\r\n if (!expiry) {\r\n return false;\r\n }\r\n\r\n if (expiry && Date.now() > +expiry) {\r\n this.clearUser();\r\n return false;\r\n }\r\n\r\n return true;\r\n }\r\n\r\n getCurrentUser(): Observable {\r\n return this.http.get(`${baseURL}user/current?include=63`);\r\n }\r\n\r\n updateUserProfile(updateData: UserProfileUpdate): Observable {\r\n return this.http.put(`${baseURL}user`, updateData);\r\n }\r\n\r\n changeAvatar(formData: FormData): Observable {\r\n return this.http.put(`${baseURL}user/change-avatar`, formData);\r\n }\r\n\r\n deleteAvatar(): Observable {\r\n return this.http.delete(`${baseURL}user/avatar`);\r\n }\r\n\r\n changePassword(pass: ChangePassword): Observable{\r\n return this.http.put(`${baseURL}user/change-password`, pass);\r\n }\r\n\r\n changePublicVisibility(): Observable {\r\n return this.http.put(`${baseURL}/user/change-public-visibility`, null);\r\n }\r\n\r\n}\r\n"], "mappings": ";;;;;;;;;;;;;;;;;AAaM,IAAO,cAAP,MAAO,aAAW;EAMtB,YAC+B,aACrB,MACA,qBAAsC;AAFjB,SAAA,cAAA;AACrB,SAAA,OAAA;AACA,SAAA,sBAAA;AARF,SAAA,mBAAmB,IAAI,QAAO;AAC/B,SAAA,iBAAiB,KAAK,iBAAiB,aAAY;AAElD,SAAA,YAAqB;AAO3B,SAAK,oBAAoB,UAAU,UAAU,CAAC,SAAoB;AAChE,WAAK,iBAAiB,KAAK,IAAI;IACjC,CAAC;AAED,SAAK,YAAY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