supabase_auth_package 0.0.2 copy "supabase_auth_package: ^0.0.2" to clipboard
supabase_auth_package: ^0.0.2 copied to clipboard

A Flutter package for Supabase authentication, supporting email/password and Google Sign-In.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:google_sign_in/google_sign_in.dart';
import 'package:supabase_auth_package/supabase_auth_pack.dart';
import 'package:supabase_flutter/supabase_flutter.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  await Supabase.initialize(
    url: 'your-supabase-url',
    anonKey: 'your-anon-key',
  );

  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Supabase Authentication',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const AuthPage(),
    );
  }
}

class AuthPage extends StatefulWidget {
  const AuthPage({super.key});

  @override
  State<AuthPage> createState() => _AuthPageState();
}

class _AuthPageState extends State<AuthPage> {
  final _authRepo = AuthRepository(supabaseClient: Supabase.instance.client);

  // For demonstration only. Replace with TextEditingController in real app
  final String demoEmail = 'test@example.com';
  final String demoPassword = 'password123';

  Future<void> _signInWithGoogle() async {
    final googleService = GoogleAuthService(
      supabaseClient: Supabase.instance.client,
      googleSignIn: GoogleSignIn(
        serverClientId: 'your-server-client-id',
      ),
    );

    await googleService.signIn();
  }

  Future<void> _signInWithEmail() async {
    await _authRepo.signInUsingEmailPassword(
      email: demoEmail,
      password: demoPassword,
      checkPhoneVerification: false // you can set it as par your requirement
    );
  }

  Future<void> _signUpWithEmail() async {
    await _authRepo.signUpUsingEmailPassword(
      email: demoEmail,
      password: demoPassword,
    );
  }

  Future<void> _checkEmailVerification() async {
    await _authRepo.checkEmailVerify(
      email: demoEmail,
      password: demoPassword,
    );
  }

  Future<void> _checkOtpVerification() async {
    await _authRepo.verifyOTP(
     countryCode: 'Your-country-code', // like 91
      phoneNumber: 'your-number', // like 9876543210
      otp: 'otp-you-received' // like 123456
    );
  }



  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Supabase Auth Example'),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            ElevatedButton(
              onPressed: _signInWithGoogle,
              child: const Text('Login with Google'),
            ),
            const SizedBox(height: 20),
            ElevatedButton(
              onPressed: _signInWithEmail,
              child: const Text('Login with Email'),
            ),
            const SizedBox(height: 20),
            ElevatedButton(
              onPressed: _signUpWithEmail,
              child: const Text('Sign Up with Email'),
            ),
            const SizedBox(height: 20),
            ElevatedButton(
              onPressed: _checkEmailVerification,
              child: const Text('Check Email Verification'),
            ),
            const SizedBox(height: 20),
            ElevatedButton(
              onPressed: _checkOtpVerification,
              child: const Text('Verify OTP'),
            )
          ],
        ),
      ),
    );
  }
}
5
likes
130
points
52
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter package for Supabase authentication, supporting email/password and Google Sign-In.

Repository

Documentation

API reference

License

MIT (license)

Dependencies

flutter, google_sign_in, supabase_flutter

More

Packages that depend on supabase_auth_package