testera_auth 0.1.0 copy "testera_auth: ^0.1.0" to clipboard
testera_auth: ^0.1.0 copied to clipboard

A Flutter plugin for code-based authentication with Firebase Cloud Functions integration.

Testera Auth #

A Flutter plugin for code-based authentication with Firebase Cloud Functions integration.

Features #

  • Code-based authentication system
  • Firebase Cloud Functions integration
  • Local storage for authentication state
  • Configurable expiration duration
  • Rate limiting protection
  • Support for both Android and iOS

Getting started #

Add this to your package's pubspec.yaml file:

dependencies:
    testera_auth: ^0.1.0

Usage #

  1. Wrap your app with TesteraAuth:
import 'package:flutter/material.dart';
import 'package:testera_auth/testera_auth.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return TesteraAuth(
      validationUrl: 'YOUR_FIREBASE_FUNCTION_URL',
      child: MaterialApp(
        title: 'My App',
        home: const HomePage(),
      ),
    );
  }
}
  1. Configure your Firebase Cloud Function:
const functions = require("firebase-functions");
const admin = require("firebase-admin");
admin.initializeApp();

exports.validateCode = functions.https.onRequest(async (req, res) => {
    const { code } = req.body;

    try {
        const codeRef = admin.firestore().collection("access_codes").doc(code);
        const codeDoc = await codeRef.get();

        if (!codeDoc.exists) {
            return res.status(400).json({ error: "Invalid code" });
        }

        const codeData = codeDoc.data();
        if (codeData.used) {
            return res.status(400).json({ error: "Code already used" });
        }

        const expiresAt = codeData.expiresAt.toDate();
        if (expiresAt < new Date()) {
            return res.status(400).json({ error: "Code expired" });
        }

        await codeRef.update({ used: true });
        return res.status(200).json({ success: true });
    } catch (error) {
        console.error("Error validating code:", error);
        return res.status(500).json({ error: "Internal server error" });
    }
});

Configuration #

The TesteraAuth widget accepts the following parameters:

  • validationUrl (required): The URL of your Firebase Cloud Function for code validation
  • expirationDuration (optional): How long the authentication should remain valid (default: 7 days)
  • initialCode (optional): A code to validate immediately when the app starts

Example #

Check out the example directory for a complete working example.

Contributing #

Contributions are welcome! Please feel free to submit a Pull Request.

License #

This project is licensed under the MIT License - see the LICENSE file for details.

0
likes
150
points
6
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter plugin for code-based authentication with Firebase Cloud Functions integration.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, http, shared_preferences

More

Packages that depend on testera_auth

Packages that implement testera_auth