Mu
Search
⌃K
🧙♂

User Authentication

All Mu apps come with built-in with User Authentication.

Getting Started

All user authentication logic is located within in mu.user. When a user is logged in to mu.app their session will also be available from within your application.

Authenticating the user

When a user first lands on your app their details will not be available to you. You will first need to call mu.user.authenticate()
Once this is complete, the user will then be available to your app. This is to help you control the flow, as fetching the users details is asynchronous.
Here is an example:
<script>
async function main() {
await mu.user.authenticate()
// Once complete the user is available.
const user = mu.user.getUser()
// Run your app logic...
}
main()
</script>

The user

Here is an example of a logged in user:
{
created: "1686737802",
id: "683d319b-59db-4129-84f2-4662cc48bd02",
profile: {
profilePicture: 'profile-picture.jpg'
},
updated: "1690380034"
username: "username"
verification_date: "1690380034"
verified: true
}
​

mu.user

mu.user.authenticate()
Promise<void>
Used to authenticate the user. Authenticate is usually run when your app is first rendered (this is only needed if you need your user to be authenticated within your application).
mu.user.getUser()
getUser: () => User | undefined
Call this function to get the currently logged in user. Will return undefined if you haven't previously called authenticate or the user is not logged in.
mu.user.authenticated
`boolean`
Returns a boolean as to whether the authenticate call has previously finished. This is helpful to test that the user is not logged in.