Skip to content

Instantly share code, notes, and snippets.

Avatar

Christian Lüdemann lydemann

View GitHub Profile
@lydemann
lydemann / course-content.component.ts
Created Feb 23, 2021
course-content.component.ts
View course-content.component.ts
private getTrustedVideoUrl(url: string): SafeResourceUrl {
// Url domains are whitelisted using CSP header
// Content-Security-Policy: frame-src <source> <source>;
const sanitizedUrl = this.sanitizer.sanitize(
SecurityContext.URL,
url
);
return this.sanitizer.bypassSecurityTrustResourceUrl(sanitizedUrl);
}
@lydemann
lydemann / course-content.component.ts
Created Feb 22, 2021
course-content.component.ts
View course-content.component.ts
private getTrustedVideoUrl(url: string): SafeResourceUrl {
// Url domains are whitelisted using CSP header
// Content-Security-Policy: frame-src <source> <source>;
const sanitizedUrl = this.sanitizer.sanitize(
SecurityContext.RESOURCE_URL,
url
);
return this.sanitizer.bypassSecurityTrustResourceUrl(sanitizedUrl);
}
View school-id.resolver.ts
@Injectable({ providedIn: 'root' })
export class SchoolIdResolver implements Resolve<null> {
constructor(private courseFacadeService: CourseFacadeService) {}
resolve(
route: ActivatedRouteSnapshot
): Observable<null> | Promise<null> | null {
const schoolId = route.params.schoolId;
auth().tenantId = schoolId;
return;
View user-resolvers.ts
setLessonCompleted: (
parent,
{ uid, lessonId, isCompleted },
context: RequestContext
) => {
if (!context.auth.admin && uid !== context.auth.uid) {
throw new AuthenticationError('User is not admin or user');
}
return firestoreDB
@lydemann
lydemann / app.routing.ts
Last active Dec 29, 2020
app.routing.ts
View app.routing.ts
const routes: Routes = [
{
path: ':schoolId',
resolve: [SchoolIdResolver],
children: [
{
path: '',
pathMatch: 'full',
redirectTo: 'courses'
},
@lydemann
lydemann / set-token.interceptor.ts
Created Dec 28, 2020
set-token.interceptor.ts
View set-token.interceptor.ts
@Injectable({ providedIn: 'root' })
export class SetTokenInterceptor implements HttpInterceptor {
constructor(private userService: UserService) {}
intercept(
req: HttpRequest<any>,
next: HttpHandler
): Observable<HttpEvent<any>> {
if (!this.userService.currentUser$.value) {
return next.handle(req);
View server.ts
const verifyToken = async ({ authorization, schoolid }) => {
if (authorization) {
const newToken = authorization.replace('Bearer ', '');
const header = await admin
.auth()
.verifyIdToken(newToken)
.then(decodedToken => {
if (decodedToken.firebase.tenant !== schoolid) {
throw new AuthenticationError("User doesn't have access to school");
}
View course.routing.ts
const routes: Routes = [
{
path: `:${selectedSectionIdRouteParam}`,
canActivate: [AuthGuard],
resolve: [CourseResolver],
component: CourseComponent,
children: [
{
path: `action-items`,
component: ActionItemsComponent,
View router.selectors.ts
import { ActivatedRouteSnapshot } from '@angular/router';
import * as fromRouter from '@ngrx/router-store';
import { createFeatureSelector, createSelector } from '@ngrx/store';
export interface State {
router: fromRouter.RouterReducerState;
}
export const selectRouter = createFeatureSelector<
State,
@lydemann
lydemann / todo-list-sandbox.service.ts
Created Jun 20, 2020
todo-list-sandbox.service.ts
View todo-list-sandbox.service.ts
public todoListChanged(affectedIds: string[]) {
this.store.dispatch(
TodoListActions.todoListChanged({
affectedIds,
}),
);
}