-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into 134-filter-by-fields
- Loading branch information
Showing
5 changed files
with
136 additions
and
27 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
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,33 @@ | ||
import AdminBookingDetails from "components/composite/AdminBookingDetails/AdminBookingDetails" | ||
import About from "pages/About" | ||
import Admin from "pages/Admin" | ||
import Booking from "pages/Booking" | ||
import Checkout from "pages/Checkout" | ||
import Contact from "pages/Contact" | ||
import Events from "pages/Events" | ||
import Home from "pages/Home" | ||
import Login from "pages/Login" | ||
import Profile from "pages/Profile" | ||
import Register from "pages/Register" | ||
import Thanks from "pages/Thanks" | ||
import { JSX } from "react" | ||
|
||
export interface RouteProps { | ||
path: string | ||
element: JSX.Element | ||
} | ||
|
||
export const AllRoutes: RouteProps[] = [ | ||
{ path: "/", element: <Home /> }, | ||
{ path: "/about", element: <About /> }, | ||
{ path: "/events", element: <Events /> }, | ||
{ path: "/contact", element: <Contact /> }, | ||
{ path: "/register", element: <Register /> }, | ||
{ path: "/login", element: <Login /> }, | ||
{ path: "/checkout", element: <Checkout /> }, | ||
{ path: "/booking", element: <Booking /> }, | ||
{ path: "/profile", element: <Profile /> }, | ||
{ path: "/admin", element: <Admin /> }, | ||
{ path: "/thanks", element: <Thanks /> }, | ||
{ path: "/admin/bookings", element: <AdminBookingDetails /> } | ||
] |
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,39 @@ | ||
import { auth } from "business-layer/security/Firebase" | ||
import AuthService from "./AuthService" | ||
import { UserRecord } from "firebase-admin/auth" | ||
|
||
describe("AuthService Integration Tests", () => { | ||
it("deletes a user", async () => { | ||
await auth.createUser({ uid: "test" }) | ||
new AuthService().deleteUser("test") | ||
let user | ||
try { | ||
user = await auth.getUser("test") | ||
} catch {} | ||
expect(user).toBe(undefined) | ||
}) | ||
|
||
it("creates a user", async () => { | ||
const createdUser = await new AuthService().createUser("[email protected]") | ||
let user | ||
try { | ||
user = await auth.getUser(createdUser.uid) | ||
} catch {} | ||
expect(createdUser).toEqual(user) | ||
expect(user.email).toEqual("[email protected]") | ||
}) | ||
|
||
it("sets custom claim on a user", async () => { | ||
const authService: AuthService = new AuthService() | ||
let createdUser: UserRecord = await authService.createUser("[email protected]") | ||
|
||
try { | ||
await authService.setCustomUserClaim(createdUser.uid, "member") | ||
} catch {} | ||
|
||
// refresh user record to get access to newly added custom claim | ||
createdUser = await auth.getUser(createdUser.uid) | ||
|
||
expect(createdUser.customClaims.member).not.toBe(undefined) | ||
}) | ||
}) |
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,50 @@ | ||
import { UserRecord } from "firebase-admin/auth" | ||
import { auth } from "business-layer/security/Firebase" | ||
import { AuthServiceClaims } from "business-layer/utils/AuthServiceClaims" | ||
|
||
export default class AuthService { | ||
/** | ||
* Deletes a user account from the Firebase Authentication Service. | ||
* @param uid | ||
*/ | ||
public async deleteUser(uid: string): Promise<void> { | ||
try { | ||
await auth.deleteUser(uid) | ||
} catch (err) { | ||
console.error("Error deleting user", err) | ||
throw err | ||
} | ||
} | ||
|
||
/** | ||
* Creates a new user account in the Firebase Authentication Service. | ||
* @param args | ||
* @param claimRole | ||
*/ | ||
public async createUser(email: string): Promise<UserRecord> { | ||
// get the user record | ||
let userRecord: UserRecord | ||
try { | ||
userRecord = await auth.createUser({ email }) | ||
} catch (err) { | ||
console.error("Error creating user", err) | ||
throw err | ||
} | ||
|
||
return userRecord | ||
} | ||
|
||
public async setCustomUserClaim( | ||
uid: string, | ||
role: typeof AuthServiceClaims.MEMBER | typeof AuthServiceClaims.ADMIN | ||
) { | ||
let userRecord: UserRecord | ||
try { | ||
userRecord = await auth.getUser(uid) | ||
auth.setCustomUserClaims(userRecord.uid, { [role]: true }) | ||
} catch (err) { | ||
console.error("Error setting custom claim on user", err) | ||
throw err | ||
} | ||
} | ||
} |
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,4 @@ | ||
export const AuthServiceClaims = { | ||
MEMBER: "member", | ||
ADMIN: "admin" | ||
} as const |