firebase-edge-auth
v1.1.0
Published
Firebase token decoder for edge runtimes
Downloads
5
Maintainers
Readme
Firebase Edge Auth
Firebase token decoder for edge runtimes, written in TypeScript.
Installation
npm install firebase-edge-auth
Usage
import { decodeFirebaseToken, FirebaseTokenError } from "firebase-edge-auth";
const projectId = "your-firebase-project-id";
const token = "user-provided-token";
try {
const decodedToken = await decodeFirebaseToken(token, projectId);
console.log("Decoded token:", decodedToken);
} catch (error) {
if (error instanceof FirebaseTokenError) {
console.error("Token verification failed:", error.message);
} else {
console.error("Unexpected error:", error);
}
}
API
decodeFirebaseToken(token: string, projectId: string): Promise<FirebaseTokenPayload>
Decodes and verifies a Firebase JWT token.
token
: The Firebase JWT token to decode.projectId
: Your Firebase project ID.
Returns a Promise that resolves to the decoded token payload if verification succeeds, or rejects with a FirebaseTokenError
if verification fails.
FirebaseTokenPayload
An interface representing the decoded token payload:
interface FirebaseTokenPayload {
aud: string;
iss: string;
sub: string;
auth_time: number;
exp: number;
iat: number;
[key: string]: any;
}
FirebaseTokenError
A custom error class for Firebase token verification failures.
License
MIT