Skip to content

The client-side library for the MikroAuth magic link authentication service.

License

Notifications You must be signed in to change notification settings

mikaelvesavuori/mikroauth-client

Repository files navigation

MikroAuth client library

A client-side library for the MikroAuth magic link authentication service. You will have to point the client to the endpoint of your MikroAuth server.

The minified version is ~4KB, substantially smaller than clients for common authentication services like Firebase (~118KB).

Quick Start

In your HTML:

<script src="path/to/mikroauth-client.min.js"></script>
<script>
  const auth = new MikroAuthClient({ authUrl: 'https://auth.example.com' });

  const isAuthenticated = await auth.isAuthenticated();
  console.log('Is authenticated?', isAuthenticated);

  const userInfo = await auth.getUserInfo();
  console.log('User info:', userInfo);
</script>

API Reference

requestMagicLink

await auth.requestMagicLink(email);

Request a new magic link email to the specified email address.

handleMagicLink

await auth.handleMagicLink();

Handle magic link from URL. Used when verifying the URL params (token and email).

isAuthenticated

await auth.isAuthenticated();

Checks if the user is authenticated.

getUserInfo

await auth.getUserInfo();

Retrieves user data.

refreshToken

await auth.refreshToken();

Get a new refresh token.

logout

await auth.logout();

Log out (sign out) the user.

Development

Build

Run npm run build. Files are created in the lib directory.

Test

Run npm test.

License

MIT. See the LICENSE file.

About

The client-side library for the MikroAuth magic link authentication service.

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Sponsor this project