Browse Source

refactoring

feature/ssr-migration-schematic
erdemcaygor 1 year ago
parent
commit
3b74410a7d
  1. 7
      npm/ng-packs/packages/oauth/src/lib/services/browser-token-storage.service.ts
  2. 10
      npm/ng-packs/packages/oauth/src/lib/strategies/auth-code-flow-strategy.ts

7
npm/ng-packs/packages/oauth/src/lib/services/browser-token-storage.service.ts

@ -14,24 +14,23 @@ export class BrowserTokenStorageService implements OAuthStorage {
} }
setItem(key: string, data: string): void { setItem(key: string, data: string): void {
console.log(key);
this.writeCookie(key, data); this.writeCookie(key, data);
} }
readCookie(name: string): string | null { readCookie(name: string): string | null {
if (typeof document === 'undefined') return null; // SSR'de yok if (typeof document === 'undefined') return null;
const match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)')); const match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)'));
return match ? decodeURIComponent(match[2]) : null; return match ? decodeURIComponent(match[2]) : null;
} }
writeCookie(name: string, value: string, days = 7): void { writeCookie(name: string, value: string, days = 7): void {
if (typeof document === 'undefined') return; // SSR'de yok if (typeof document === 'undefined') return;
const expires = new Date(Date.now() + days * 86400000).toUTCString(); const expires = new Date(Date.now() + days * 86400000).toUTCString();
document.cookie = `${name}=${encodeURIComponent(value)}; expires=${expires}; path=/; Secure; SameSite=Lax`; document.cookie = `${name}=${encodeURIComponent(value)}; expires=${expires}; path=/; Secure; SameSite=Lax`;
} }
removeCookie(name: string): void { removeCookie(name: string): void {
if (typeof document === 'undefined') return; // SSR'de yok if (typeof document === 'undefined') return;
document.cookie = `${name}=; Max-Age=0; path=/;`; document.cookie = `${name}=; Max-Age=0; path=/;`;
} }
} }

10
npm/ng-packs/packages/oauth/src/lib/strategies/auth-code-flow-strategy.ts

@ -31,13 +31,9 @@ export class AuthCodeFlowStrategy extends AuthFlowStrategy {
} }
private checkRememberMeOption() { private checkRememberMeOption() {
console.log('checkRememberMeOption called ---->>>>>');
const accessToken = this.oAuthService.getAccessToken(); const accessToken = this.oAuthService.getAccessToken();
console.log('accessToken New ----->>>>', accessToken);
const isTokenExpire = isTokenExpired(this.oAuthService.getAccessTokenExpiration()); const isTokenExpire = isTokenExpired(this.oAuthService.getAccessTokenExpiration());
console.log('isTokenExpire New ----->>>>', isTokenExpire);
let rememberMe = this.rememberMeService.get(); let rememberMe = this.rememberMeService.get();
console.log('rememberMe New ----->>>>', rememberMe);
if (accessToken && !rememberMe) { if (accessToken && !rememberMe) {
const rememberMeValue = this.rememberMeService.getFromToken(accessToken); const rememberMeValue = this.rememberMeService.getFromToken(accessToken);
@ -82,7 +78,6 @@ export class AuthCodeFlowStrategy extends AuthFlowStrategy {
} }
protected listenToTokenReceived() { protected listenToTokenReceived() {
console.log('listenToTokenReceived');
if (isPlatformBrowser(this.platformId)) { if (isPlatformBrowser(this.platformId)) {
this.oAuthService.events this.oAuthService.events
.pipe( .pipe(
@ -98,8 +93,6 @@ export class AuthCodeFlowStrategy extends AuthFlowStrategy {
} }
navigateToLogin(queryParams?: Params) { navigateToLogin(queryParams?: Params) {
console.log('navigateToLogin');
console.log(isPlatformBrowser(this.platformId));
if (isPlatformBrowser(this.platformId)) { if (isPlatformBrowser(this.platformId)) {
let additionalState = ''; let additionalState = '';
if (queryParams?.returnUrl) { if (queryParams?.returnUrl) {
@ -112,7 +105,6 @@ export class AuthCodeFlowStrategy extends AuthFlowStrategy {
} }
checkIfInternalAuth(queryParams?: Params) { checkIfInternalAuth(queryParams?: Params) {
console.log('checkIfInternalAuth');
if (isPlatformBrowser(this.platformId)) { if (isPlatformBrowser(this.platformId)) {
this.oAuthService.initCodeFlow('', this.getCultureParams(queryParams)); this.oAuthService.initCodeFlow('', this.getCultureParams(queryParams));
return false; return false;
@ -129,8 +121,6 @@ export class AuthCodeFlowStrategy extends AuthFlowStrategy {
} }
login(queryParams?: Params) { login(queryParams?: Params) {
console.log('login');
console.log(isPlatformBrowser(this.platformId));
if (isPlatformBrowser(this.platformId)) { if (isPlatformBrowser(this.platformId)) {
this.oAuthService.initCodeFlow('', this.getCultureParams(queryParams)); this.oAuthService.initCodeFlow('', this.getCultureParams(queryParams));
return of(null); return of(null);

Loading…
Cancel
Save