Skip to content

Instantly share code, notes, and snippets.

@larrybotha
larrybotha / machine.js
Last active October 22, 2019 14:00
Generated by XState Viz: https://xstate.js.org/viz
// Luna Med auth machine
const fetchMachine = Machine({
id: 'auth',
initial: 'unknown',
states: {
unknown: {
entry: 'storeRequestUrl',
@larrybotha
larrybotha / machine.js
Last active October 4, 2019 22:51
Generated by XState Viz: https://xstate.js.org/viz
const bullishMachineConfig = {
initial: 'findingStock',
on: {
MARKET_TRENDING_DOWN: 'bearish',
MARKET_TRENDING_SIDEWAYS: 'evaluatingGeneralMarket',
},
states: {
findingStock: {
@larrybotha
larrybotha / A.markdown
Last active May 6, 2024 11:22
XState + AWS Amplify example

XState + AWS Amplify example

A breakdown of a project that uses XState to manage state for authenticating a user with Cognito, and then finding the authorized application user with an invoked machine.

  1. create auth machine
  2. create auth context
  3. handle AWS authentication
  4. once user authenticates with Cognito, redirect to user route to get user from db
  5. at user route use userMachine service from authMachine to get application user
  6. once associated application user is found, send user to organization route to allow user to associate session with specific organization
@larrybotha
larrybotha / machine.js
Last active October 25, 2019 00:00
Generated by XState Viz: https://xstate.js.org/viz
// LunaMed organization authorisation
const fetchTargets = [{target: 'select', cond: 'hasOrgs'}, {target: 'fetching'}];
const xeroTokenExchangeTargets = [
{target: '#org.xeroSelect.exchangingToken', cond: 'hasOrgs'},
{target: 'fetchingOrgsForXeroTokenExchange'},
];
@larrybotha
larrybotha / machine.js
Created October 22, 2019 14:02
Generated by XState Viz: https://xstate.js.org/viz
// Luna Med user auth machine
const authUserMachine = Machine({
id: 'user',
initial: 'noUser',
context: {
error: undefined,
user: undefined,