The Fleek Login Button provides standalone authentication button component with an embedded modal that functions independently of host application.
authToken
obtained via Dynamic dialog is exchanged for an accessToken
using the generateUserSessionDetails
mutation. The accessToken
is then stored as a cookie with the same name. Any app under the hostname can read the cookie and use it to perform GraphQL requests.
- π€ Install
- π·ββοΈDevelopment
- π§Έ Basic Usage
- π Additional Notes
- π Docs
- π Package Release
- π Contributing
- β±οΈ Changelog
- Nodejs as runtime
- NPM, Yarn to install the SDK, or PNPM for development
- Familiarity with Nodejs, Frontend/Client side development
Install the package by executing:
npm i @fleek-platform/login-button
For a quick start, learn the basic usage.
For developers looking to contribute to the @fleek-platform/login-button
, clone the repository and follow the contribution guide.
For runtime we utilize Nodejs and PNPM as the package manager.
Next, install the project dependencies:
pnpm i
Create a dotenv file containing the required environment variables for development.
touch .env
Open your favourite text editor to edit the file.
Here's an example for staging environent variable values:
PUBLIC_GRAPHQL_API_URL="https://graphql.service.fleek.xyz/graphql"
PUBLIC_DYNAMIC_ENVIRONMENT_ID="de23a5f0-aaa5-412e-8212-4fb056a3b30d"
PUBLIC_DASHBOARD_APP_URL="https://fleek.xyz/dashboard"
PUBLIC_UI_AGENTS_APP_URL="https://fleek.xyz/agents"
Since npm link is a command-line tool for symlinking a local package as a dependency during development. It is commonly used for testing packages before publishing them. But it's common to cause confusion and unexpected behaviour.
Instead of using pnpm link
for local package testing, use the following command, that's closer to release install.
pnpm generate:local_package
Once successful, the console will display an install command that you can copy and run in your project.
Here's an example that uses npm:
npm i --no-save <GENERATED_FILE_PATH>
Warning
Remove concurrent package name from package.json, e.g. @fleek-platform/agents-ui. The local install doesn't save or modify the package.json. The package.json and lockfiles are only for existing registry versions. You might have to run the clean command to remove any conflicting packages from node_modules, locks, etc.
Alternatively, if you're using an npm-compatible package manager like pnpm, avoid saving or modifying the lock file, e.g:
npm_config_save=false npm_config_lockfile=false pnpm i <GENERATED_FILE_PATH>
Manage the versioning of changelog entries.
Declare an intent to release by executing the command and answering the wizard's questions:
pnpm changeset:add
Make use of the exported LoginProvider
component. Exposed props are: login
, logout
, accessToken
, isLoading
and error
.
You need to set the following required props:
<LoginProvider
graphqlApiUrl="..."
environmentId="..."
//...
/>
You can import the LoginProvider
and useAuthStore
. The provider allows you to customize the CTA buttons, e.g. log in.
import { LoginProvider, useAuthStore } from '@fleek-platform/login-button';
While the useAuthStore
has actions and state, e.g. accessToken and setShowLogin.
// Use authentication store
const {
// Toggle login modal
setShowLogin,
// Trigger logout
setTriggerLogout,
// Update accessToken by Project ID
updateAccessTokenByProjectId,
// Check if newUser
isNewUser,
} = useAuthStore();
The graphqlApiUrl
and dynamicEnvironmentId
can be overriden. Otherwise, it'll default to the environment the distribution is built to target, e.g. staging or production.
// Staging
const graphqlApiUrl = 'https://graphql.service.staging.fleeksandbox.xyz/graphql';
const dynamicEnvironmentId = 'c4d4ccad-9460-419c-9ca3-494488f8c892';
const onAuthenticationSuccess = () => console.log('onAuthenticationSuccess callback!');
// Use Login provider
<LoginProvider
graphqlApiUrl={graphqlApiUrl}
dynamicEnvironmentId={dynamicEnvironmentId}
onAuthenticationSuccess={onAuthenticationSuccess}
>
{(props) => {
const { login, logout, accessToken, isLoading, error } = props;
const handleClick = () => {
if (Boolean(accessToken)) {
logout();
} else {
login();
}
};
let buttonText = 'Login with Dynamic';
switch (true) {
case Boolean(error):
buttonText = 'Login failed';
break;
case isLoading:
buttonText = 'Loading...';
break;
// not a real session, session is in the cookie, just for demo
case Boolean(accessToken):
buttonText = 'Log out';
break;
}
return (
<>
<Button onClick={handleClick}>{buttonText}</Button>
{accessToken && <p className="max-w-64 break-words mt-4">accessToken: {accessToken}</p>}
</>
);
}}
</LoginProvider>;
To read auth cookie value at any point getAuthCookie()
utility is exposed. Auth cookie uses accessToken
key.
import { getAuthCookie } from '@fleek-platform/login-button';
const accessToken: string | undefined = getAuthCookie();
Currently the generateUserSessionDetails
mutation is called using a simple fetch
call in fetchGenerateUserSessionDetails.ts due to the fact that @fleek-platform/utils-genql-client
package breaks the build. Once the issue is resolved, the existing implementation should be restored from this point in Git history commit.
TLDR; Use the Release by develop hash. The main branch must have a linear strategy, e.g. we don't want contributors to push directly to main. At anytime, it should be a subset of develop, as we are strictly about preventing source diversion. On production release, the package should be available at npmjs.org, for staging GitHub Registry packages (GHCR).
The main principal to understand is that when a branch is merged into main or develop, the npm-publisher.yml workflow is triggered to publish packages to the appropriate registry.
For the main branch, packages are published to the npmjs.org registry, ensuring they are available for public use.
Conversely, when changes are merged into the develop branch, packages are published to the GitHub Registry packages (GHCR) , which serves as a staging environment.
This setup allows for a clear separation between production-ready packages and those in development.
You can release to production following a linear strategy. This assumes that the convention "main" branch is of linear history and is a subset of the "develop" branch commit history. For example, the team is happy to have "develop" as where the latest version of the project exists, that "main" shouldn't diverge and only contain commits from "develop".
Use-case examples:
- The team has merged some feature branches into develop identified as commit hash "abc123" and want to release upto to the commit history hash "abc123" onto "main". By doing this they expect the build process to occur and deploy into the Fleek Platform
- The team has merged several feature branches into develop identified as commit hashes
commitFeat1
,commitFeat2
andcommitFeat3
by this historical order. It's decided to release everything in commit history untilcommitFeat1
, but notcommitFeat2
andcommitFeat3
. Although, it'd be wiser to keep the feature branches in pending state as "develop" should always be in a ready state for testing and release as the team may want to release some quick hotfixes, etc
To release to production open the actions tab here.
Select the "π Release by develop hash" job in the left sidebar. Next, select the "Run workflow" drop-down and provide the required details, e.g. the commit hash of develop branch
you are interested. Do note that it'll release everything up until the commit hash you select. If you have anything in develop which's not ready, that should be reverted from develop branch
.
You can override the organisation registry in different ways. For example, you can setup a local .npmrc
that overrides the organisation @fleek-platform
registry.
Start by changing to project directory and create or edit a .npmrc file:
touch .npmrc
Use your favourite text editor and put the following content:
//npm.pkg.github.com/:_authToken=$PAT
@fleek-platform:registry=https://npm.pkg.github.com
The PAT
is an environment variable for your private authentication token. An authentication token is required for GHCR Registry, as GHCR is our private registry used for testing.
Alternatively, some users prefer to use the npm CLI to authenticate against the organisation scope.
Here's a quick set of instructions to allow to login via NPM CLI.
- Execute the command npm login with scope and registry URL
npm login --scope=@fleek-platform --registry=https://npm.pkg.github.com
- Provide a random username, e.g. somebody
username: somebody
- Put the provided token as the user password
password: ***
Onwards, your registry for @fleek-platform
will be pointing to private GitHub Registry. Make sure that you logout after testing, as this might cause confusion.
Visit your GitHub user tokens.
Create a new token that allows you to:
- Upload packages to GitHub Package Registry, e.g.
write:packages
- Download packages from GitHub Package Registry, e.g.
read:packages
This section guides you through the process of contributing to our open-source project. From creating a feature branch to submitting a pull request, get started by:
- Fork the project here
- Create your feature branch using our branching strategy, e.g.
git checkout -b feat/my-new-feature
- Run the tests:
pnpm test
- Commit your changes by following our commit conventions, e.g.
git commit -m 'chore: π€ my contribution description'
- Push to the branch, e.g.
git push origin feat/my-new-feature
- Create new Pull Request following the corresponding template guidelines
The develop branch serves as the main integration branch for features, enhancements, and fixes. It is always in a deployable state and represents the latest development version of the application.
Feature branches are created from the develop branch and are used to develop new features or enhancements. They should be named according to the type of work being done and the scope of the feature and in accordance with conventional commits here.
We prefer to commit our work following Conventional Commits conventions. Conventional Commits are a simple way to write commit messages that both people and computers can understand. It help us keep track fo changes in a consistent manner, making it easier to see what was added, changed, or fixed in each commit or update.
The commit messages are formatted as [type]/[scope] The type is a short descriptor indicating the nature of the work (e.g., feat, fix, docs, style, refactor, test, chore). This follows the conventional commit types.
The scope is a more detailed description of the feature or fix. This could be the component or part of the codebase affected by the change.
Here's an example of different conventional commits messages that you should follow:
test: π Adding missing tests
feat: πΈ A new feature
fix: π A bug fix
chore: π€ Build process or auxiliary tool changes
docs: π Documentation only changes
refactor: π‘ A code change that neither fixes a bug or adds a feature
style: π Markup, white-space, formatting, missing semi-colons...