mirror of
https://github.com/rowyio/rowy.git
synced 2026-05-18 05:05:28 +02:00
18 lines
500 B
TypeScript
18 lines
500 B
TypeScript
import * as functions from "firebase-functions";
|
|
|
|
export const hasAnyRole = (
|
|
authorizedRoles: string[],
|
|
context: functions.https.CallableContext
|
|
) => {
|
|
if (!context.auth || !context.auth.token.roles) return false;
|
|
const userRoles = context.auth.token.roles as string[];
|
|
const authorization = authorizedRoles.reduce(
|
|
(authorized: boolean, role: string) => {
|
|
if (userRoles.includes(role)) return true;
|
|
else return authorized;
|
|
},
|
|
false
|
|
);
|
|
return authorization;
|
|
};
|