<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Charlotte Neill on Medium]]></title>
        <description><![CDATA[Stories by Charlotte Neill on Medium]]></description>
        <link>https://medium.com/@charlotteneill?source=rss-46577340c1b6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*UO5SYNppuL8XFeeH</url>
            <title>Stories by Charlotte Neill on Medium</title>
            <link>https://medium.com/@charlotteneill?source=rss-46577340c1b6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 22:42:11 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@charlotteneill/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Why Elm Might Be a Better Choice Than React for Your Next Web Project]]></title>
            <link>https://medium.com/mind-gym-tech/why-elm-might-be-a-better-choice-than-react-for-your-next-web-project-7342713c090?source=rss-46577340c1b6------2</link>
            <guid isPermaLink="false">https://medium.com/p/7342713c090</guid>
            <category><![CDATA[elm]]></category>
            <category><![CDATA[elm-lang]]></category>
            <category><![CDATA[state-management]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Charlotte Neill]]></dc:creator>
            <pubDate>Mon, 04 Sep 2023 15:59:38 GMT</pubDate>
            <atom:updated>2023-09-04T15:59:38.771Z</atom:updated>
            <content:encoded><![CDATA[<p>In the ever-evolving landscape of web development, the choices we make regarding our technology stack can profoundly impact the success of our projects. React, with its vast ecosystem and popularity, has long been a go-to choice for front-end development. Its flexibility and versatility have made it the darling of many developers.</p><p>Yet, in our quest for the best tools, it’s easy to overlook hidden gems that might offer unique advantages. One such gem is Elm, a functional programming language for building web applications. While it may not boast the same level of mainstream recognition as React, Elm presents a compelling case for consideration.</p><p>I’ve had the pleasure and privilege of working with Elm for over four years, during which I’ve not only honed my Elm skills but also seamlessly integrated Elm with React applications, led projects, and contributed to applications now in commercial use.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wwKiA8K8pkOQMh3hkVRN2w.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@alexisamz?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Alexis AMZ DA CRUZ</a> on <a href="https://unsplash.com/photos/IIL9OUXzXhc?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p><strong>In this blog post, we’re going to explore why Elm might just be a better choice than React for your web development endeavours.</strong> We’ll delve into Elm’s simplicity, its robust type system, the support of its dedicated community, and a debugging tool that could change the way you approach troubleshooting in your projects.</p><h3>The Simplicity Advantage</h3><p>In an era where the JavaScript ecosystem offers a myriad of libraries, frameworks, and build tools, decision fatigue can set in quickly. React is known for its flexibility, but this can lead to endless choices: which state management library to use? How to structure your components? What’s the preferred way to handle side effects?</p><p>Enter Elm, a language that actively discourages such dilemmas. Elm’s design philosophy aligns with the mantra that “there should be one, and preferably only one, obvious way to do it” (a principle akin to Python’s). This minimalism extends from the language to its ecosystem.</p><p>With Elm, you’ll find a tightly knit collection of libraries and tools that are intentionally crafted to work together. This cohesion results in a straightforward development experience with fewer forks in the road. Elm’s small and curated ecosystem reduces decision-making complexity, allowing you to focus on building your application.</p><p>Moreover, Elm’s learning curve, often cited as a challenge, is unique in that it’s steep but surprisingly short. The language itself is compact and designed to be simple. Once you grasp its core concepts, you’ll find that you can work proficiently in Elm with ease. Compare this to React’s expansive landscape, where mastering the entire ecosystem can be a more extended endeavour.</p><p>Simplicity doesn’t just manifest in the choice of tools; it permeates your codebase. With Elm, immutability is enforced, and state changes are made via pure functions that produce new state instances. This simplicity contributes to code that is predictable, easy to test, and less prone to bugs.</p><h3>Strong Typing and Reliability</h3><p>Imagine a world where runtime errors are a thing of the past, where your codebase is free from null reference exceptions, type-related mishaps, and NaN cannot propagate through your code. Elm offers precisely this kind of assurance, thanks to its robust type system and the guarantees it provides through its compiler.</p><p>Elm’s type system is your guardian for application reliability. It eliminates the possibility of runtime errors entirely. If a piece of code compiles in Elm, it’s a guarantee that it will work as intended when your application runs. This level of certainty can save you hours of debugging and testing.</p><p>Consider, for example, the common problem of null or undefined values. In JavaScript and React, handling these cases can be a source of bugs. Elm eliminates this issue by design. If a value can potentially be null, it must be explicitly declared as such, and Elm forces you to handle these cases explicitly.</p><p>Furthermore, Elm’s type system makes your code more self-documenting. When reading Elm code, you can often discern the shape and purpose of data structures and functions just by examining their types. This self-documenting nature is a gift to you, your team, and anyone who comes across your code in the future.</p><p>Reliability extends beyond preventing errors. It leads to confidence in your codebase, enabling you to make changes and refactorings without the constant fear of breaking something unintentionally. Elm code is like a well-constructed fortress: solid, secure, and ready to withstand the test of time.</p><h3>Supportive Community and Resources</h3><p>Every technology is only as strong as its community, and Elm boasts a community that is both passionate and supportive. If you embark on an Elm journey, you’ll have thousands of fellow Elm enthusiasts by your side, ready to answer questions, provide guidance, and share in your triumphs.</p><p>One standout feature of Elm’s community support is the dedicated Elm Slack channel. Here, you’ll find a bustling hub of knowledge sharing and problem solving. Whether you’re a newcomer with a basic question or a seasoned Elm veteran facing a complex challenge, you’ll discover a warm welcome and the help you need.</p><p>Additionally, the Elm package ecosystem, while smaller than JavaScript’s, is known for its quality and reliability. Elm’s emphasis on community review and semantic versioning ensures that packages work well together and are well-maintained. Elm’s package manager, known as “elm-package,” makes it easy to discover, install, and manage packages for your project. It enforces strict versioning constraints to ensure that your project stays reliable and predictable over time.</p><h3>A Time-Travelling Debugger</h3><p>Debugging is an inevitable part of software development, but it doesn’t have to be a painful one. Elm introduces a game-changing tool in the form of its time-traveling debugger. This tool allows you to step through your application’s state changes and see how your code evolves over time.</p><p>With Elm’s debugger, you can rewind and replay user interactions, inspect the state at different points in time, and understand how actions flow through your application. It’s like having a DVR for your code, and it’s incredibly valuable for diagnosing and fixing issues.</p><p>This debugging capability isn’t just a fancy feature; it fundamentally changes the way you approach troubleshooting. Instead of adding console logs or using trial-and-error to identify problems, you can systematically investigate the behavior of your application, pinpoint issues with precision, and confidently make changes knowing that you’re not introducing new bugs.</p><p>While React offers various debugging tools, Elm’s time-traveling debugger stands out for its comprehensiveness and ease of use. It’s a powerful asset that can save you time and frustration in the debugging process.</p><h3>Conclusion</h3><p>In this exploration of Elm’s merits compared to React, we’ve uncovered a language that offers a refreshing departure from the norm. Elm’s simplicity, robust type system, supportive community, and time-traveling debugger are compelling reasons to embrace it as the superior choice for modern web development.</p><p>It’s important to recognise that Elm’s advantages aren’t mere possibilities; they are guarantees. With Elm, you can wave goodbye to runtime errors, confidently refactor code, and enjoy a development experience that’s as smooth as it is reliable.</p><p>Elm offers an alternative that goes beyond the status quo. Elm isn’t just a technology; it’s a philosophy — a commitment to code that is dependable, maintainable, and a joy to work with.</p><p>So, as you embark on your next web development journey, consider Elm not as an alternative, but as a bold choice that puts the power of reliability and simplicity firmly in your hands. Your codebase will thank you, your users will reap the rewards, and your development journey will be defined by reliability and simplicity.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7342713c090" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mind-gym-tech/why-elm-might-be-a-better-choice-than-react-for-your-next-web-project-7342713c090">Why Elm Might Be a Better Choice Than React for Your Next Web Project</a> was originally published in <a href="https://medium.com/mind-gym-tech">MindGym Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Elm with AWS Cognito]]></title>
            <link>https://medium.com/@charlotteneill/elm-with-aws-cognito-8eae4fb858d0?source=rss-46577340c1b6------2</link>
            <guid isPermaLink="false">https://medium.com/p/8eae4fb858d0</guid>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[elm]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[aws-cognito]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Charlotte Neill]]></dc:creator>
            <pubDate>Fri, 28 Dec 2018 23:13:49 GMT</pubDate>
            <atom:updated>2018-12-28T23:13:49.564Z</atom:updated>
            <content:encoded><![CDATA[<p>In this tutorial, we will create an elm app that signs up a user at a click of a button. We will go through creating a cognito user pool, javascript interop, ports to send messages to javascript and to Elm, and displaying information back to the user based on whether the sign up was successful or not.</p><p><strong>Create a new AWS Cognito User pool</strong></p><p>Amazon Cognito provides authentication, authorization, and user management for web apps. AWS Cognito allows 50,000 users for free, after that the price is $0.00550 per user.</p><p><strong>In AWS Cognito, create a user pool;</strong></p><p>1. From the AWS Console click Services then select Cognito under Mobile Services.</p><p>2. Choose Manage your User Pools.</p><p>3. Choose Create a User Pool</p><p>4. Provide a name for your user pool such as HomeBaking, then select Review Defaults</p><p>5. On the review page, click Create pool.</p><p>6. Note the Pool Id of your newly created user pool.</p><p><strong>Generate an app client id;</strong></p><p>1. From the Pool Details page for your user pool, select App clients from the left General Settings section in the navigation bar</p><p>2. Choose Add an app client.</p><p>3. Give the app client a name, name it the web application you wish to use the pool for e.g. HomeBakingWebApp</p><p>4. Uncheck the Generate client secret option.</p><p>5. Choose Create app client.</p><p>6. Note the App client id.</p><p><strong>Installing AWS Cognito tools and dependencies</strong></p><p>1. Open your preferred text editor and add a package.json with the following:</p><pre>{<br> &quot;private&quot;: true<br>}</pre><p>2. Install the Amazon Cognito Identity SDK for JavaScript and the Webpack tool into your project:</p><pre>&gt; npm install --save-dev webpack json-loader<br>&gt; npm install --save amazon-cognito-identity-js</pre><p>3. Create a webpack.config.js:</p><pre>module.exports = {                                                <br>  entry: &#39;/Users/charlotteneill/myApp/src/entry&#39;,<br>  output: {<br>      path: &#39;/Users/charlotteneill/myApp/dist&#39;,<br>      filename: &#39;my-app.js&#39;<br>  },<br>  module: {<br>      rules: [<br>          {<br>              test: /\.json$/,<br>              loader: &#39;json&#39;<br>          }<br>      ]<br>  }<br>};</pre><p><em>Note: Paths must be absolute.</em></p><p>4. Add the following to your package.json:</p><pre>&quot;scripts&quot;: {<br>   &quot;build&quot;: &quot;webpack&quot;<br> }</pre><p>5. Create an src/entry.js file.</p><p>6. And run `npm run build’, typing ‘Y’ when asked to install webpack-cli.</p><p>7. This should compile successfully.</p><p><strong>Cognito sign up code</strong></p><p>As specified in our webpack.config.js file, dist/my-app.js is generated on build of entry.js, so to test the code we add to entry.js, we can create a html file with a script pointing to dist/my-app.js.</p><p><strong>Test the sign up code to add an unverified user to our user pool:</strong></p><p>1. Create a new file called cognito.html, containing the following:</p><pre>&lt;html&gt;<br>&lt;head&gt;<br>  &lt;script src=&quot;dist/my-app.js&quot;&gt;&lt;/script&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>  (Body)<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>2. Add a new file, ids/cognito_ids.js, with the following code:</p><pre>module.exports = {<br>   clientId: &#39;&#39;, <em>// your app client id</em><br>   userPoolId: &#39;&#39;, <em>// your user pool id</em><br>};</pre><p>3. Replace the empty strings in cognito_ids.js with your client app id and the user pool id. These are the two ids we took note of earlier, after creating the Cognito user pool.</p><p>4. In entry.js, add the following:</p><pre><em>//Set up Cognito</em><br><strong>var</strong> cognitoUserPoolIds = require(&#39;../ids/cognito_ids&#39;);<br><strong>var</strong> AmazonCognitoIdentity = require(&#39;amazon-cognito-identity-js&#39;);<br><strong>var</strong> CognitoUserPool = AmazonCognitoIdentity.CognitoUserPool;</pre><pre><strong>var</strong> poolData = {<br>  UserPoolId: cognitoUserPoolIds.userPoolId,<br>  ClientId: cognitoUserPoolIds.clientId<br>};</pre><pre><strong>var</strong> userPool = <strong>new</strong> CognitoUserPool(poolData);<br><strong>var</strong> attributeList = [];</pre><pre><strong>var</strong> dataEmail = {<br>  Name: &#39;email&#39;,<br>  Value: &#39;test@email.com&#39;<br>};</pre><pre><strong>var</strong> attributeEmail = <strong>new</strong> AmazonCognitoIdentity.CognitoUserAttribute(dataEmail);<br>attributeList.push(attributeEmail);</pre><pre>userPool.signUp(&#39;testUsername&#39;, &#39;Testpassword1!&#39;, attributeList, null, <strong>function</strong> (err, result) {<br>  <strong>if</strong> (err) {<br>      <strong>var</strong> errorMessage = err.message || JSON.stringify(err);<br>      app.ports.errors.send(errorMessage);<br>      <strong>return</strong>;<br>  }</pre><pre>  <strong>var</strong> cognitoUser = result.user;<br>  app.ports.signupSuccess.send({ username: cognitoUser.getUsername() });<br>});</pre><p>The above code, creates a new unconfirmed user that exists in your pool with email address, ‘test@email.com’, username, ‘testUsername’ and password, ‘Testpassword1!’ Unconfirmed meaning signed up but not verified.</p><p><strong>Running the code:</strong></p><p>1. Build the project using `npm run build`</p><p>2. Execute the command `elm reactor` in a terminal. `elm reactor` creates a development server on port 8000.</p><p>3. In a new browser tab, type in `<a href="http://localhost:8000/cognito.html">http://localhost:8000/cognito.html</a>`</p><p>We should now see a new user created with username, ‘testUsername’ in our AWS Cognito app:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*P1BLqMAFM9iEZhMf" /></figure><p>This means we now have working sign up code that can be used in our Elm Application.</p><p><strong>Elm Application</strong></p><p>Create a new Elm application.</p><p>1. Ensure you have Elm version 0.19.</p><p>2. Create src/Main.elm file.</p><p>3. Create a new file, elm-cognito.html, with the following code in it:</p><pre>&lt;html&gt;<br>&lt;head&gt;<br>  &lt;script src=&quot;elm.js&quot;&gt;&lt;/script&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>  &lt;div id=&quot;elm&quot;&gt;&lt;/div&gt;<br>  &lt;script src=&quot;dist/my-app.js&quot;&gt;&lt;/script&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>4. Comment out all code in the src/entry.js file</p><p>5. Add the following at the bottom of the src/entry.js file:</p><pre><em>// Set up Elm</em><br><strong>var</strong> app = Elm.Main.init({<br>  node: document.getElementById(&#39;elm&#39;)<br>});</pre><p>6. Add the following code in Main.elm:</p><pre>module Main exposing (..)</pre><pre>import Browser<br>import Html exposing (Html, input, text, br, div, h1, button, label)<br>import Html.Events exposing (onClick)</pre><pre>---- MODEL ----</pre><pre>type Model<br> = LoggedOut</pre><pre>initialModel : Model<br>initialModel =<br> LoggedOut</pre><pre>init : ( Model, Cmd Msg )<br>init =<br> ( initialModel, Cmd.none )</pre><pre>---- UPDATE ----</pre><pre>type Msg<br>  = DoSignUp</pre><pre>update : Msg -&gt; Model -&gt; ( Model, Cmd Msg )<br>update msg model =<br>  case model of<br>      LoggedOut  -&gt;<br>          case msg of<br>              DoSignUp -&gt;<br>                  ( model, Cmd.none )</pre><pre>---- VIEW ----</pre><pre>view : Model -&gt; Html Msg<br>view model =<br> case model of<br>     LoggedOut -&gt;<br>         div []<br>             [ h1 [] [ text &quot;Welcome! Please sign up.&quot; ]<br>             , button<br>                 [ onClick (DoSignUp) ]<br>                 [ text &quot;Sign up&quot; ]<br>             ]</pre><pre>---- PROGRAM ----</pre><pre>main : Program () Model Msg<br>main =<br>  Browser.element<br>      { view = view<br>      , init = \_ -&gt; init<br>      , update = update<br>      , subscriptions = always Sub.none<br>      }</pre><p>The above code has initial state as LoggedOut and the view which contains the elm code needed to render the ‘sign up’ button to the screen. We have a msg ‘DoSignUp’ that is sent to the update function when the ‘Sign up’ button is clicked. Currently in the update function, ‘DoSignUp’ does nothing.</p><p>Run the Elm application:</p><p>1. Execute the command ‘elm init’ in a terminal</p><p>2. Build entry.js, `npm run build`</p><p>3. Build the project using `elm make src/Main.elm — output=elm.js`</p><p>4. Execute the command `elm reactor` in a terminal.</p><p>5. In a new browser tab, type in `<a href="http://localhost:8000/elm-cognito.html">http://localhost:8000/elm-cognito.html</a>`.</p><p>You should see this appear in the browser tab:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/387/0*3U7bxDaUN8vgi7-r" /></figure><p>Currently, our ‘Sign up’ button does nothing, so the next step is to call our sign up code that we commented out in entry.js. In order to do this, we need our Elm application to interact with javascript through ports.</p><p><strong>On the Elm side, we must set up a port that can send information to javascript:</strong></p><p>1. Create a Cognito.elm file containing the following:</p><pre>port module Cognito exposing (signup, errors, signupSuccess)</pre><pre>port signup : { emailAddress: String, password: String, username: String } -&gt; Cmd msg</pre><pre>port errors : (String -&gt; msg) -&gt; Sub msg</pre><pre>port signupSuccess : ({ username: String} -&gt; msg) -&gt; Sub msg</pre><p>In the above code, we have defined 3 ports.</p><p>In the javascript code, we can subscribe to these ports so that when a message is sent, we can perform a certain action, in javascript.</p><p><strong>Perform sign up on sending sign up message in javascript:</strong></p><p>1. Replace the current code in entry.js with the following:</p><pre><em>//Set up Cognito</em><br><strong>var</strong> cognitoUserPoolIds = require(&#39;../ids/cognito_ids&#39;);<br><strong>var</strong> AmazonCognitoIdentity = require(&#39;amazon-cognito-identity-js&#39;);<br><strong>var</strong> CognitoUserPool = AmazonCognitoIdentity.CognitoUserPool;</pre><pre><strong>var</strong> poolData = {<br>UserPoolId: cognitoUserPoolIds.userPoolId, <em>// Your user pool id here</em><br>ClientId: cognitoUserPoolIds.clientId <em>// Your client id here</em><br>};</pre><pre><strong>var</strong> userPool = <strong>new</strong> CognitoUserPool(poolData);</pre><pre><em>// Set up Elm</em><br><strong>var</strong> app = Elm.Main.init({<br>node: document.getElementById(&#39;elm&#39;)<br>});</pre><pre><em>// what happens on sign up</em><br>app.ports.signup.subscribe(<strong>function</strong> (data) {<br><em>// callback for port - sign up</em><br>console.log(&#39;data: &#39; + JSON.stringify(data));</pre><pre><strong>var</strong> attributeList = [];</pre><pre><strong>var</strong> dataEmail = {<br>  Name: &#39;email&#39;,<br>  Value: data.emailAddress<br>};</pre><pre><strong>var</strong> attributeEmail = <strong>new</strong> AmazonCognitoIdentity.CognitoUserAttribute(dataEmail);</pre><pre>attributeList.push(attributeEmail);<br>userPool.signUp(data.username, data.password, attributeList, null, <strong>function</strong> (err, result) {</pre><pre>  <strong>if</strong> (err) {<br>    <strong>var</strong> errorMessage = err.message || JSON.stringify(err);<br>    console.log(errorMessage);<br>    <strong>return</strong>;<br>  }</pre><pre>  <strong>var</strong> cognitoUser = result.user;<br>  console.log(‘Username is ’+cognitoUser.getUsername());<br>});</pre><pre>});</pre><p>In the above code, the function app.ports.signup.subscribe is subscribing to the signup port we created in Cognito.elm and on receiving a signup message, we’re calling the signup logic to create an unconfirmed user in our Cognito user pool (this is the code we tested earlier, modified to use the data we send along with the signup message).</p><p><strong>Send signup message from Elm:</strong></p><p>1. In Main.elm, import Cognito.elm. Add import Cognito under import Html.Events exposing (onClick)</p><p>2. In Main.elm, Replace ‘<em>DoSignUp -&gt; ( model, Cmd.None)</em>’ with</p><pre>DoSignUp -&gt;<br>     ( model, Cognito.signup ({ emailAddress = &quot;test2@email.com&quot;,<br>                   password = &quot;Password1!&quot;,<br>                   username = &quot;testUsername2&quot; }) ).</pre><p>This is the code that sends a message using the signup port containing our data — we could make this data come from user input on the screen, but for the purposes of this tutorial, we are hard-coding the values.</p><p>3. Build and run the Elm application.</p><p>4. On the network tab, you should see a call to a cognito sign up endpoint:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/472/0*W4kI4lSnfkG9QLGI" /></figure><p>With the payload containing the data sent from Elm:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/430/0*CMR8DyDNL4XuGcOb" /></figure><p>And there should be a new user in your user pool with username, ‘testUsername2’:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*WNAGEwZNaLbUfGa2" /></figure><p>We now need to send information back to Elm so the application can do something after the Cognito endpoint is called, in this case, that will be either, displaying the username to the user or displaying an error.</p><p><strong>Sending information to Elm:</strong></p><p>1. Subscribe to ports in Elm. In Main.elm, replace subscriptions = always Sub.none with</p><pre>subscriptions = \model -&gt;<br>          Sub.batch<br>              [ Cognito.signupSuccess CognitoSignupSuccess<br>              , Cognito.errors CognitoError<br>           ]</pre><p>, we’re subscribing to two ports: signupSuccess and errors.</p><p>2. Add Elm messages that take the information in the form it is given. Add two messages to the enum Msg so your enum looks like:</p><pre>type Msg<br>= DoSignUp<br>| CognitoError String<br>| CognitoSignupSuccess { username: String }</pre><p>3. Handle these messages in your update so your update looks like this:</p><pre>CognitoError error -&gt;<br>       ( LoggedOut error, Cmd.none )</pre><pre>CognitoSignupSuccess { username } -&gt;<br>       ( LoggedOut (&quot;Thanks for signing up, &quot;++username++&quot;!&quot;), Cmd.none )</pre><p>4. Amend src/entry.js to send the messages to Elm after sign up.</p><pre>app.ports.signup.subscribe(<strong>function</strong> (data) {<br><strong>var</strong> attributeList = [];<br></pre><pre><strong>var</strong> dataEmail = {<br>  Name: &#39;email&#39;,<br>  Value: data.emailAddress<br>};</pre><pre><strong>var</strong> attributeEmail = <strong>new</strong> AmazonCognitoIdentity.CognitoUserAttribute(dataEmail);</pre><pre>attributeList.push(attributeEmail);</pre><pre>userPool.signUp(data.username, data.password, attributeList, null, <strong>function</strong> (err, result) {<br>  <strong>if</strong> (err) {<br>    <strong>var</strong> errorMessage = err.message || JSON.stringify(err);<br>    app.ports.errors.send(errorMessage);<br>    <strong>return</strong>;<br>  }</pre><pre>  <strong>var</strong> cognitoUser = result.user;<br>  app.ports.signupSuccess.send({ username: cognitoUser.getUsername() });<br>});</pre><pre>});</pre><p>Note in the above code, instead of logging out the error and username, we are sending a message through our errors port if an error has occured from sign up and sending a message through our signupSuccess port is no error occured.</p><p>5. Update the view logic in Main.elm to display the error/success message sent to us from the javascript code.</p><pre>view : Model -&gt; Html Msg</pre><pre>view model =<br> case model of<br>     LoggedOut message -&gt;<br>         div []<br>             [ h1 [] [ text (<br>                 case message of<br>                  &quot;&quot; -&gt;<br>                      &quot;Welcome! Please sign up.&quot;</pre><pre>                  _ -&gt;<br>                      message<br>             )]<br>             , button<br>                 [ onClick (DoSignUp) ]<br>                 [ text &quot;Sign up&quot; ]<br>             ]</pre><p>6. In Main.elm, update all other instances of LoggedOut to have a string parameter, this will need to be updated in the Model and initialModel. The code of Main.elm should look like the following:</p><pre>module Main exposing (..)</pre><pre>import Browser<br>import Html exposing (Html, input, text, br, div, h1, button, label)<br>import Html.Events exposing (onClick)<br>import Cognito</pre><pre>---- MODEL ----</pre><pre>type Model<br> = LoggedOut String</pre><pre>initialModel : Model<br>initialModel =<br> LoggedOut &quot;&quot;</pre><pre>init : ( Model, Cmd Msg )<br>init =<br> ( initialModel, Cmd.none )</pre><pre>---- UPDATE ----</pre><pre>type Msg<br>  = DoSignUp<br>  | CognitoError String<br>  | CognitoSignupSuccess { username : String }</pre><pre>update : Msg -&gt; Model -&gt; ( Model, Cmd Msg )<br>update msg model =<br>  case model of<br>      LoggedOut _  -&gt;<br>          case msg of<br>              DoSignUp -&gt;<br>                  ( model, Cognito.signup ({ emailAddress = &quot;test2@email.com&quot;,<br>                               password = &quot;Password1!&quot;,<br>                               username = &quot;testUsername2&quot; }) )</pre><pre>              CognitoError error -&gt;<br>                  ( LoggedOut error, Cmd.none )</pre><pre>              CognitoSignupSuccess { username } -&gt;<br>                  ( LoggedOut (&quot;Thanks for signing up, &quot;++username++&quot;!&quot;),<br>                                    Cmd.none )</pre><pre>---- VIEW ----</pre><pre>view : Model -&gt; Html Msg<br>view model =<br> case model of<br>     LoggedOut message -&gt;<br>         div []<br>             [ h1 [] [ text (<br>                 case message of<br>                  &quot;&quot; -&gt;<br>                      &quot;Welcome! Please sign up.&quot;</pre><pre>                  _ -&gt;<br>                      message<br>             )]<br>             , button<br>                 [ onClick (DoSignUp) ]<br>                 [ text &quot;Sign up&quot; ]<br>             ]</pre><pre>---- PROGRAM ----</pre><pre>main : Program () Model Msg<br>main =<br>  Browser.element<br>      { view = view<br>      , init = \_ -&gt; init<br>      , update = update<br>      , subscriptions = \model -&gt;<br>          Sub.batch<br>              [ Cognito.signupSuccess CognitoSignupSuccess<br>              , Cognito.errors CognitoError<br>              ]<br>      }</pre><p>7. Build javascript and Elm files. Run Elm Application.</p><p>8. After clicking the ‘sign up’ button, you should see the heading change to.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/302/0*-2fUG7ostcq4jt9r" /></figure><p>This is because, we have not changed the username in our call to Cognito.signup</p><p>1. Change</p><pre>DoSignUp -&gt;<br>    ( model, Cognito.signup ({ emailAddress = &quot;test2@email.com&quot;,<br>                  password = &quot;Password1!&quot;,<br>                  username = &quot;testUsername2&quot; }) )</pre><p>so ‘testUsername2’ is ‘testUsername3’.</p><p>2. Build and run Elm Application.</p><p>3. Should see the following, after clicking ‘sign up’:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/567/0*PuCjH_5jw7PtO2dL" /></figure><p>Try amending the call to Cognito.signup in Elm.main, by supplying an invalid email address, or changing the password to not include a symbol and see the outputs generated by clicking the ‘Sign in’ button.</p><p>So, there you have it. In summary, we have</p><ul><li>Created a Cognito user pool</li><li>Used the aws cognito library to create an unconfirmed user with email address, username and password in javascript.</li><li>Created cognito ports in Elm used for sending one-way messages from Elm, to javascript and from javascript, to Elm.</li><li>Amended an Elm app to send messages to javascript.</li><li>Implemented callback functionality in javascript so our response from Cognito could be sent to Elm, in a format Elm understands.</li><li>In Elm, handled the response sent from javascript and displayed the response in our app.</li></ul><p><strong>Links</strong></p><p>For verifying a user, logging in, logging out and deleting a user in Cognito, code snippets to do so can be found here, <a href="https://github.com/aws-amplify/amplify-js/tree/master/packages/amazon-cognito-identity-js">https://github.com/aws-amplify/amplify-js/tree/master/packages/amazon-cognito-identity-js</a>, under usages.</p><p>For the full code and user input of username, email address and password, see: <a href="https://github.com/charlottemn93/elm-with-aws-incognito">https://github.com/charlottemn93/elm-with-aws-incognito</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8eae4fb858d0" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>