Mastering Flutter Authentication with Strapi CMS: A Step-by-Step Guide

Authentication is the process by which a user verifies their identity to access specific resources in an application. Typically, this involves logging in with a username and password. The client submits these credentials, and the server then compares them against its database to confirm the user's identity.


This is a companion discussion topic for the original entry at https://strapi.io/blog/mastering-flutter-authentication-with-strapi-cms-a-step-by-step-guide

Hi there, i followed along, but i am running into an error

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Null check operator used on a null value

which is for this line of code

List<User> users = (await ApiService().getUsers())!;

can’t seem to find a solution/fix to correct this.

any help would be much appreciated

Hey! :slight_smile:

I’ve got some issues, is here something missing?

  1. the dotenv will not be initialized?
    await dotenv.load(fileName: “.env”);
    is missing in the main.dart

  2. if i try to register a user, i get the error that “role” is a necessary field? There isnt a single word about roles in this article - but yeah, in the model “user” in strapi that field is required. When using postman, you’ll get the same error as in Flutter. In Strapi there are two default roles “Public” and “Authenticated”. But i cant hand over any of these in the body of my post-request?

Would appreciate some more information on that topic :slight_smile:

Kind regards,
Alex

After further investigation:

In a standard installation of Strapi, the “User & Permission”-Plugin is now activated from the start on.
So a simple post to the endpoint /users will have the role field as mandatory. But with that plugin you shouldn’t trigger the endpoint directly.

Instead trigger the url /auth/local/register for SignUp and /auth/local for SignIn.

how is it save to login a user by getting the list of users and checking if it has the same email as you filled in without checking the password? Or am I missing something?