npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@orange-games/phaser-amazon-cognito

v0.1.2

Published

A Phaser plugin that adds User Login/Sync support trough Amazon Cognito Identity/Syn

Downloads

15

Readme

Phaser Amazon Cognito

A Phaser plugin that adds user register/login support trough amazon cognito.

Key Features:

  • Works on mobile and desktop
  • Included TypeScript support
  • Async library with promise calls
  • Easy to use as phaser plugin

Getting Started

First you want to get a fresh copy of the plugin. You can get it from this repo or from npm, ain't that handy.

npm install @orange-games/phaser-amazon-cognito --save-dev

Next up you'd want to add it to your list of js sources you load into your game:

<script src="path/to/phaser-amazon-cognito.js"></script>

After adding the script to the page you can activate it by enabling the plugin:

game.add.plugin(Fabrique.Plugins.Cognito);

#####Note If you are using typescript, you have to user typescript 2.0.0 or higher for the promises to work.

Usage

First off you want to set the user pool info using the userPoolId and clientId.

game.cognito.setPoolInfo('<your_pool_id>', '<your_client_id>');

#####Registration Register a new user to the user pool.

game.cognito.register('<username>', '<password>', '<email>', null).then(function(user) {
    console.log('Registration worked!', user);
}).catch(function(error) {
    console.log('Registration failed:', error);
});

#####Confirm Registration An account has to be confirmed after registration. The code will be in the inbox of the users email.

game.cognito.confirmRegistration('<confirmation_code>').then(function() {
    console.log('Confirmation worked!');
}).catch(function(error) {
    console.log('Confirmation failed:', error);
});

#####Resend Confirmation Resend conformation mail to users email. Will only work if user is not confirmed yet.

game.cognito.resendConfirmation().then(function() {
    console.log('Confirmation resend!');
}).catch(function(error) {
    console.log('Failed to resend confirmation:', error);
});

#####Reset Password Sends a reset code to the user's email address.

game.cognito.resetPassword().then(function() {
    console.log('Password has been reset!');
}).catch(function(error) {
    console.log('Failed to reset password:', error);
});

#####Confirm Password Reset Use the reset code given in the reset email to change password.

game.cognito.confirmResetPassword('<confirmation_code>', '<new_password>').then(function() {
    console.log('Password has been changed!');
}).catch(function(error) {
    console.log('Failed to change password:', error);
});

#####Change Password Changes the password for the current user. The user has to be logged in.

game.cognito.changePassword('old_password', 'new_password').then(function() {
    console.log('Password has been change!');
}).catch(function(error) {
    console.log('Failed to change password:', error);
});

#####Login Logs in a user from the user pool.

game.cognito.login('<username>', '<password>').then(function(state) {
    console.log('LoggedIn!', state.user, state.sessionToken);
}).catch(function(error) {
    console.log('Login failed:', error);
});

#####Logout Logs out a user from the user pool.

game.cognito.logout();

#####Loading User From LocalStorage Loads the userState from the localStorage on the device.

game.cognito.loadStorageUser();

#####Validate Session Checks if a session has been set. Does not actually check if the user is logged in. Can be used to check if the loadedStorageUser had a session.

game.cognito.validateSession().then(function() {
    console.log('Valid session!');
}).catch(function(error) {
    console.log('Invalid session:', error);
});

#####Setting User Most commands will use the last used user, if you want to call verify on a different user for example you need to call this first. Login or register will automatically set this.

game.cognito.setUser('<username>');

Credits

This library uses the amazon-cognito-identity-js library provided by amazon. (https://github.com/aws/amazon-cognito-identity-js)

Disclaimer

We at OrangeGames just love playing and creating awesome games. We aren't affiliated with Phaser.io. We just needed some awesome login handling in our awesome HTML5 games. Feel free to use it for enhancing your own awesome games!

Phaser Amazon Cognito is distributed under the MIT license. All 3rd party libraries and components are distributed under their respective license terms.