@ciridae/auth 0.1.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/createCiridaeAuth.js +4 -5
- package/dist/entries/client.d.ts +1 -0
- package/dist/entries/client.js +1 -0
- package/dist/principal.d.ts +22 -0
- package/dist/principal.js +24 -0
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getApps, initializeApp } from "firebase/app";
|
|
2
|
-
import { getAuth,
|
|
2
|
+
import { getAuth, onAuthStateChanged, signInWithCustomToken, signOut as firebaseSignOut, } from "firebase/auth";
|
|
3
3
|
import { AuthenticatedUserSchema } from "./authenticatedUser.js";
|
|
4
4
|
import { buildCiridaeSignInUrl, buildCiridaeSignOutUrl, } from "./authServiceUrls.js";
|
|
5
5
|
const FIREBASE_APP_NAME = "ciridae-browser-auth";
|
|
@@ -8,7 +8,8 @@ const LOCAL_DEVELOPMENT_USER = AuthenticatedUserSchema.parse({
|
|
|
8
8
|
displayName: "Local Developer",
|
|
9
9
|
email: "dev-only-auth-bypass@ciridae.dev",
|
|
10
10
|
emailVerified: true,
|
|
11
|
-
|
|
11
|
+
// A fixture photo for local auth bypass, never used for Firebase sessions.
|
|
12
|
+
photoURL: "https://images.unsplash.com/photo-1472099645785-5658abf4ff4e?auto=format&fit=crop&w=96&h=96&q=80",
|
|
12
13
|
uid: LOCAL_DEVELOPMENT_TOKEN,
|
|
13
14
|
});
|
|
14
15
|
export function createCiridaeAuth(configuration) {
|
|
@@ -84,9 +85,7 @@ function createFirebaseAuth(identityConfiguration, authServiceConfiguration) {
|
|
|
84
85
|
: null;
|
|
85
86
|
},
|
|
86
87
|
async subscribe(onAuthenticatedUser) {
|
|
87
|
-
|
|
88
|
-
await setPersistence(firebaseAuth, inMemoryPersistence);
|
|
89
|
-
return onAuthStateChanged(firebaseAuth, (user) => {
|
|
88
|
+
return onAuthStateChanged(getFirebaseAuth(), (user) => {
|
|
90
89
|
onAuthenticatedUser(user ? AuthenticatedUserSchema.parse(user) : null);
|
|
91
90
|
});
|
|
92
91
|
},
|
package/dist/entries/client.d.ts
CHANGED
package/dist/entries/client.js
CHANGED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* The signed-in user's role and permissions as the app's own backend returns them.
|
|
4
|
+
* Matches `ciridae.auth.Principal`; use it to hide actions, never to authorize.
|
|
5
|
+
*/
|
|
6
|
+
export declare const PrincipalSchema: z.ZodObject<{
|
|
7
|
+
email: z.core.$ZodBranded<z.ZodEmail, "UserEmail", "out">;
|
|
8
|
+
metadata: z.ZodRecord<z.ZodString, z.ZodJSONSchema>;
|
|
9
|
+
name: z.ZodNullable<z.ZodString>;
|
|
10
|
+
picture_url: z.ZodNullable<z.ZodString>;
|
|
11
|
+
organization_id: z.ZodString;
|
|
12
|
+
permissions: z.ZodArray<z.ZodString>;
|
|
13
|
+
role: z.ZodString;
|
|
14
|
+
user_id: z.core.$ZodBranded<z.ZodString, "FirebaseUid", "out">;
|
|
15
|
+
}, z.core.$strip>;
|
|
16
|
+
export type Principal = z.infer<typeof PrincipalSchema>;
|
|
17
|
+
/**
|
|
18
|
+
* Whether the principal's role carries a permission slug. Pass the project's
|
|
19
|
+
* generated `Permission` union as the type argument to type-check slugs:
|
|
20
|
+
* `can<Permission>(principal, "invoices:approve")`.
|
|
21
|
+
*/
|
|
22
|
+
export declare function can<Permission extends string = string>(principal: Principal, permission: NoInfer<Permission>): boolean;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { FirebaseUidSchema, UserEmailSchema } from "./authenticatedUser.js";
|
|
3
|
+
/**
|
|
4
|
+
* The signed-in user's role and permissions as the app's own backend returns them.
|
|
5
|
+
* Matches `ciridae.auth.Principal`; use it to hide actions, never to authorize.
|
|
6
|
+
*/
|
|
7
|
+
export const PrincipalSchema = z.object({
|
|
8
|
+
email: UserEmailSchema,
|
|
9
|
+
metadata: z.record(z.string(), z.json()),
|
|
10
|
+
name: z.string().nullable(),
|
|
11
|
+
picture_url: z.string().nullable(),
|
|
12
|
+
organization_id: z.string(),
|
|
13
|
+
permissions: z.array(z.string()),
|
|
14
|
+
role: z.string(),
|
|
15
|
+
user_id: FirebaseUidSchema,
|
|
16
|
+
});
|
|
17
|
+
/**
|
|
18
|
+
* Whether the principal's role carries a permission slug. Pass the project's
|
|
19
|
+
* generated `Permission` union as the type argument to type-check slugs:
|
|
20
|
+
* `can<Permission>(principal, "invoices:approve")`.
|
|
21
|
+
*/
|
|
22
|
+
export function can(principal, permission) {
|
|
23
|
+
return principal.permissions.includes(permission);
|
|
24
|
+
}
|