The Authentication API enables users to authenticate with your application using their Puter account.
This is essential for users to access the various Puter.js APIs integrated into your application. The auth API supports several features, including sign-in, sign-out, checking authentication status, and retrieving user information.
<html>
<body>
<script src="https://js.puter.com/v2/"></script>
<button id="sign-in">Sign in</button>
<script>
// Because signIn() opens a popup window, it must be called from a user action.
document.getElementById('sign-in').addEventListener('click', async () => {
// signIn() will resolve when the user has signed in.
await puter.auth.signIn().then((res) => {
puter.print('Signed in<br>' + JSON.stringify(res));
});
});
</script>
</body>
</html>
<html>
<body>
<script src="https://js.puter.com/v2/"></script>
<script>
puter.print(`Sign in status: ${puter.auth.isSignedIn()}`);
</script>
</body>
</html>
<html>
<body>
<script src="https://js.puter.com/v2/"></script>
<script>
puter.auth.getUser().then(function(user) {
puter.print(JSON.stringify(user));
});
</script>
</body>
</html>
<html>
<body>
<script src="https://js.puter.com/v2/"></script>
<script>
puter.auth.signOut();
</script>
</body>
</html>
These authentication features are supported out of the box when using Puter.js:
puter.auth.signIn()
- Sign in a userputer.auth.signOut()
- Sign out the current userputer.auth.isSignedIn()
- Check if a user is signed inputer.auth.getUser()
- Get information about the current userYou can see various Puter.js authentication features in action from the following examples: