-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Override firebase authentication service for local environment (#14)
* Override firebase authentication service for local environment * Override firebase storage service for local environment
- Loading branch information
Showing
11 changed files
with
159 additions
and
40 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export interface IContactFormApi { | ||
saveContact(email: string, name: string, message: string): Promise<void>; | ||
} |
20 changes: 20 additions & 0 deletions
20
apps/client/src/app/api/firebase-contact-form-api-service.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { IContactFormApi } from './contact-form-api.requirements'; | ||
import { addDoc, collection } from 'firebase/firestore'; | ||
import { initDb } from '../config/firebase'; | ||
|
||
export class FirebaseContactFormApiService implements IContactFormApi { | ||
private readonly db; | ||
|
||
public constructor() { | ||
this.db = initDb(); | ||
} | ||
|
||
|
||
public async saveContact(email: string, name: string, message: string): Promise<void> { | ||
await addDoc(collection(this.db, 'messages'), { | ||
email, | ||
name, | ||
message, | ||
}); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { IContactFormApi } from './contact-form-api.requirements'; | ||
|
||
export class LocalContactFormApiService implements IContactFormApi { | ||
public async saveContact(email: string, name: string, message: string): Promise<void> { | ||
console.log(email, name, message); | ||
} | ||
} |
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import React from 'react'; | ||
|
||
import { IContactFormApi } from '../api/contact-form-api.requirements'; | ||
import { LocalContactFormApiService } from '../api/local-contact-form-api-service'; | ||
|
||
export const ContactFormApiServiceContext = React.createContext<IContactFormApi>(new LocalContactFormApiService()); |
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
60 changes: 60 additions & 0 deletions
60
apps/client/src/app/service/local-authentication-service.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { IAuthenticationService } from './authentication.interface'; | ||
import { IUser } from '../interfaces/user.interface'; | ||
|
||
export class LocalAuthenticationService implements IAuthenticationService { | ||
private authenticatedUser: IUser | null = null; | ||
private authStateChangedCallback: ((user: IUser | null) => void) | undefined; | ||
|
||
public onAuthStateChanged(callback: (user: IUser | null) => void): () => void { | ||
this.authStateChangedCallback = callback; | ||
|
||
callback(this.authenticatedUser); | ||
|
||
return () => { | ||
this.authStateChangedCallback = undefined; | ||
} | ||
} | ||
|
||
public async login(email: string, password: string): Promise<IUser> { | ||
this.authenticatedUser = { | ||
email, | ||
displayName: null, | ||
} | ||
|
||
this.authStateChangedCallback?.call(this, this.authenticatedUser); | ||
|
||
return this.authenticatedUser; | ||
} | ||
|
||
public async register(email: string, password: string): Promise<IUser> { | ||
this.authenticatedUser = { | ||
email, | ||
displayName: null, | ||
} | ||
|
||
this.authStateChangedCallback?.call(this, this.authenticatedUser); | ||
|
||
return this.authenticatedUser; | ||
} | ||
|
||
public async loginWithGoogle(): Promise<IUser> { | ||
this.authenticatedUser = { | ||
email: '[email protected]', | ||
displayName: null, | ||
} | ||
|
||
this.authStateChangedCallback?.call(this, this.authenticatedUser); | ||
|
||
return this.authenticatedUser; | ||
} | ||
|
||
public async logout(): Promise<void> { | ||
this.authenticatedUser = null; | ||
|
||
this.authStateChangedCallback?.call(this, this.authenticatedUser); | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
public async resetPassword(email: string): Promise<void> { | ||
} | ||
} |