Giter Site home page Giter Site logo

jluse / stytch-javascript-example Goto Github PK

View Code? Open in Web Editor NEW

This project forked from stytchauth/stytch-javascript-example

0.0 1.0 0.0 2.24 MB

An example app using the Stytch Vanilla JavaScript SDK

License: MIT License

JavaScript 39.52% CSS 15.78% HTML 44.70%

stytch-javascript-example's Introduction

Stytch Vanilla JavaScript example application

Overview

This example application demonstrates how one may use Stytch within a Vanilla JavaScript application. There is a wide ecosystem of tools for building and serving JavaScript web apps each with their own implementation style and flavor. For that reason, this example is unopinionated and does not use additional tooling other than HTML, CSS, and our Vanilla JavaScript SDK. The entire application is served out of the public directory using http-server.

This project uses Stytch's JavaScript SDK which provides pre-built UI components and headless methods to securely interact with Stytch.

This application features Email Magic Links and Google OAuth for authentication, as well as our Sessions Management product to manage user sessions. You can use this application's source code as a learning resource, or use it as a jumping off point for your own project. We are excited to see what you build with Stytch!

Set up

Follow the steps below to get this application fully functional and running using your own Stytch credentials.

In the Stytch Dashboard

  1. Create a Stytch account. Once your account is set up a Project called "My first project" will be automatically created for you.

  2. Within your new Project, navigate to SDK configuration, and make the following changes:

    • Click Enable SDK.

    • Under Authorized environments add the domain http://localhost:3000.

      Authorized environments
    • Within the Email Magic Links drawer, toggle on Enable the LoginOrCreate Flow.

      SDK Email Magic Links
    • Toggle on OAuth.

      SDK OAuth
  3. Navigate to Redirect URLs, and add http://localhost:3000 as the types Login and Sign-up.

    Redirect URLs
  4. Navigate to OAuth, and set up login for Google in the Test environment. Follow all the instructions provided in the Dashboard. If you are not interested in OAuth login you can skip this step. However, the Continue with Google button in this application will not work.

    OAuth configuration
  5. Finally, navigate to API Keys, and copy your public_token. You will need this value later on.

On your machine

In your terminal clone the project and install dependencies:

git clone https://github.com/stytchauth/stytch-javascript-example.git
cd stytch-javascript-example
npm i

Next, open the file public/js/app.js and replace the value assigned to the constant STYTCH_PUBLIC_TOKEN with your public_token.

const STYTCH_PUBLIC_TOKEN = "public-token-test-123abcd-1234-1234-abcd-123123abcabc";

Running locally

After completing all the set up steps above the application can be run with the command:

npm run dev

The application will be available at http://localhost:3000.

You'll be able to login with Email Magic Links or Google OAuth and see your Stytch User object, Stytch Session, and see how logging out works.

Next steps

This example app showcases a small portion of what you can accomplish with Stytch. Here are a few ideas to explore:

  1. Add additional login methods like Passwords.
  2. Replace the pre-built UI with your own using by using the SDK's headless methods.
  3. Replace the Google OAuth button with the high converting Google One Tap UI.
  4. Secure your app further by building MFA authentication using methods like WebAuthn.
  5. Use Stytch Sessions to secure your backend.

Get help and join the community

๐Ÿ’ฌ Stytch community Slack

Join the discussion, ask questions, and suggest new features in our โ€‹Slack community!

โ“ Need support?

Check out the Stytch Forum or email us at [email protected].

stytch-javascript-example's People

Contributors

mary-stytch avatar nathan-stytch avatar snyk-bot avatar jeremy-stytch avatar allison-stytch avatar judd-stytch avatar cal-stytch avatar chris-stytch avatar julianna-stytch avatar anmol-stytch avatar lucy-stytch avatar danny-stytch avatar edwin-stytch avatar max-stytch avatar skelly-stytch avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.