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

Simple and easy JWT plugin for Gazelle.

Gazelle JWT Plugin #

The Gazelle JWT Plugin provides JSON Web Token (JWT) authentication capabilities for the Gazelle framework. This plugin allows you to easily secure your routes by integrating JWT-based authentication into your Gazelle application.

This plugin is based on dart_jsonwebtoken.

Getting started #

Installation #

To install the Gazelle JWT Plugin, add it to your pubspec.yaml file:

dependencies:
  gazelle_core: <latest-version>
  gazelle_jwt: <latest-version> 

Then, run dart pub get or flutter pub get to install the package.

Example usage #

Here's a quick example on how to use the GazelleJwtPlugin:

  final app = GazelleApp();
  await app.registerPlugin(GazelleJwtPlugin("supersecret"));

  app
    ..post(
      "/login",
      (request) async {
        return GazelleResponse(
          statusCode: 200,
          body: app.getPlugin<GazelleJwtPlugin>().sign({"test": "123"}),
        );
      },
    )
    ..get(
      "/hello_world",
      (request) async {
        return GazelleResponse(
          statusCode: 200,
          body: "Hello, World!",
        );
      },
      preRequestHooks: [app.getPlugin<GazelleJwtPlugin>().authenticationHook],
    );

  await app.start();