This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Injectable({ | |
providedIn: 'root' | |
}) | |
export class AuthGuardService implements CanActivate { | |
constructor(public cognitoService: CognitoService, public router: Router) {} | |
canActivate(): Observable<boolean> { | |
return this.cognitoService | |
.getSession() | |
.pipe(map(session => (session.isValid() ? true : false))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public savePost(post: string): Observable<any> { | |
return this.cognitoService.getAccessToken().pipe( | |
concatMap(accessToken => { | |
return this.http.post( | |
'http://localhost:3000/posts', | |
{ post }, | |
{ | |
headers: { | |
Authorization: accessToken.jwtToken | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div *ngFor="let item of [1,2,3]; let i = index" [attr.id]="'item-'+ i"> | |
{{ item }} | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Injectable } from '@angular/core'; | |
import { from, Observable, throwError } from 'rxjs'; | |
import { Auth } from 'aws-amplify'; | |
import { catchError, map } from 'rxjs/operators'; | |
@Injectable({ | |
providedIn: 'root' | |
}) | |
export class CognitoService { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AWSTemplateFormatVersion: '2010-09-09' | |
Description: 'mulperiCMS AWS infra' | |
Parameters: | |
StackName: | |
Type: String | |
Resources: | |
UserPool: | |
Type: AWS::Cognito::UserPool |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Injectable } from '@angular/core'; | |
import { | |
CognitoUserPool, | |
AuthenticationDetails, | |
CognitoUser, | |
CognitoUserSession, | |
CognitoUserAttribute, | |
CognitoAccessToken, | |
CognitoIdToken | |
} from 'amazon-cognito-identity-js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Pipe, PipeTransform } from '@angular/core'; | |
/* | |
A pipe is a class decorated with pipe metadata. | |
The pipe class implements the PipeTransform interface's transform method that accepts an input value followed by optional parameters and returns the transformed value. | |
There will be one additional argument to the transform method for each parameter passed to the pipe. Your pipe has one such parameter: the exponent. | |
To tell Angular that this is a pipe, you apply the @Pipe decorator, which you import from the core Angular library. | |
The @Pipe decorator allows you to define the pipe name that you'll use within template expressions. It must be a valid JavaScript identifier. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Directive, Input, ElementRef, OnInit } from '@angular/core'; | |
@Directive({ | |
selector: '[mulperiTooltip]', | |
}) | |
export class TooltipDirective implements OnInit { | |
@Input() mulperiDescription: string; | |
constructor(private el: ElementRef) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Will look like this: | |
{ | |
1: { <- Parent item id | |
1: { <- Child item id and item itself | |
childId: "abc" | |
} | |
} | |
} | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { saveAs } from "file-saver"; | |
import * as converter from "json-2-csv"; | |
converter.json2csv(this.items, (err, csv) => { | |
if (!err) { | |
const blob = new Blob([csv], { type: "text/csv;charset=utf-8;" }); | |
saveAs(blob, "export.csv"); | |
} else { | |
console.log("Error converting data to CSV."); | |
} |