Skip to main content

How to enable Guest Flow and Login as a Guest User?

Introduction

This guide walks you through enabling and using Guest Flow in your Flutter app with the LikeMinds SDK. Guest Flow lets users explore the app without registering, enhancing user engagement and reducing onboarding friction.

Prerequisites

Before you begin, ensure the following:

  • Basic Understanding of Flutter: Familiarity with Flutter widgets and navigation.
  • Basic knowledge of Postman or equivalent API testing tools.

Steps

Step 1: Initiate a user session

Authenticated API calls to the LikeMinds backend require an authorization token. This token can be generated using this Getting Started doc. Make sure to log in with the Community Manager's credentials.

Step 2: Enable Guest Flow in Community Settings

To enable Guest Flow, update the community settings with the following request:

curl --location --request PUT 'https://auth.likeminds.community/community/settings' \
--header 'Authorization: {cm_access_token}' \
--header 'Content-Type: application/json' \
--data '{
"community_settings": [
{
"enabled": true,
"setting_title": "Enable guest flow",
"setting_type": "enable_guest_flow"
}
]
}'

Step 3: Setup LMFeedCore in Your Flutter App

Initialize the LMFeedCore package in your main function to ensure the SDK is properly set up before running the app. Provide loginRequired callback while initializing which can be used to trigger an action when a guest user tries to restricted action.

void main() async {
// Call setup function before the runApp() function
await LMFeedCore.instance.initialize(
lmFeedCallback: LMFeedCoreCallback(
// callback function, triggered when user click
// on an action which required login
loginRequired: (context) {
// implement your action i.e show snackbar, dialogue etc.
},
),
);

runApp(YourApp());
}

Step 4: Show Feed as a Guest User

To display the feed for guest users, use the following snippet according to your authentication method:

Using API key Security (Server Side Authentication)

// Initiate user session, use the response to check for any errors
LMResponse response =
await LMFeedCore.instance.showFeedWithoutApiKey(
accessToken : "YOUR_ACCESS_TOKEN",
refreshToken : "YOUR_REFRESH_TOKEN",
);
note

Make sure to send is_guest: true while initiating a user session on your server using initiate API.

Without using API key Security (Client Side Authentication)

// Initiate user session, use the response to check for any errors
LMResponse<void> response = await LMFeedCore.instance.showFeedWithApiKey(
apiKey: "YOUR_API_KEY",
isGuest: true,
);

Step 5: Navigate to the Feed Screen

Upon a successful response, navigate to the LMFeedSocialScreen to start using the Feed in your app:

if (response.success) {
// Create route with LMFeedSocialScreen
MaterialPageRoute route = MaterialPageRoute(
builder: (context) => const LMFeedSocialScreen(),
);
// Navigate to LMFeedSocialScreen
Navigator.pushReplacement(context, route);
}
note

Make sure to logout the guest user session with logout() method from LMFeedCore before login with other user credentials.