<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Luthfi Khusyasy</title>
    <description>The latest articles on DEV Community by Luthfi Khusyasy (@khusyasy).</description>
    <link>https://dev.to/khusyasy</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F717482%2Ffe0e4083-df70-4117-a34e-d95fe4a0bcd8.png</url>
      <title>DEV Community: Luthfi Khusyasy</title>
      <link>https://dev.to/khusyasy</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/khusyasy"/>
    <language>en</language>
    <item>
      <title>How I built a fully offline ID card OCR, trained on synthetic data</title>
      <dc:creator>Luthfi Khusyasy</dc:creator>
      <pubDate>Fri, 13 Nov 2026 12:59:58 +0000</pubDate>
      <link>https://dev.to/khusyasy/how-i-built-a-fully-offline-id-card-ocr-trained-on-synthetic-data-1bb3</link>
      <guid>https://dev.to/khusyasy/how-i-built-a-fully-offline-id-card-ocr-trained-on-synthetic-data-1bb3</guid>
      <description>&lt;p&gt;I needed to read KTPs (Indonesian ID cards) for a sign-up form. OCR APIs charge per scan, and when I tried running OCR myself the results were pretty bad :/&lt;/p&gt;

&lt;p&gt;So I made my own. The catch is that KTP data is personal data, so I couldn't train on real cards. It turns out synthetic data was enough, and here is my little journey.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://ktp-kit.khusyasy.my.id/en" rel="noopener noreferrer"&gt;Live demo&lt;/a&gt; | &lt;a href="https://ktp-kit.khusyasy.my.id/en/docs" rel="noopener noreferrer"&gt;Docs&lt;/a&gt; | &lt;a href="https://ktp-kit.khusyasy.my.id/nik" rel="noopener noreferrer"&gt;Offline NIK checker&lt;/a&gt; | &lt;a href="https://github.com/Khusyasy/ktp-kit" rel="noopener noreferrer"&gt;Source code&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Setup
&lt;/h2&gt;

&lt;p&gt;Everything here ran on my laptop, no GPU.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Windows 11, Intel i7-12700H, 16GB RAM&lt;/li&gt;
&lt;li&gt;Python with PyTorch (CPU) for training, ONNX for the browser&lt;/li&gt;
&lt;li&gt;One training run takes about an hour, so I could try a few ideas in one afternoon&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Why in the browser
&lt;/h2&gt;

&lt;p&gt;Mainly because I wanted it free. If the OCR runs on the user's phone, there's no API bill and no server doing the heavy work. Every scan costs me nothing.&lt;/p&gt;

&lt;p&gt;Privacy was the other reason. A KTP photo is about the most sensitive thing a user can send you. If the reading happens on their phone, the photo doesn't have to go anywhere, and my server only gets the fields I actually need. Indonesia's data protection law (UU PDP) asks for exactly that, collect only what you need.&lt;/p&gt;

&lt;p&gt;And as a bonus, once the model is downloaded it works offline too.&lt;/p&gt;

&lt;h2&gt;
  
  
  How it works
&lt;/h2&gt;

&lt;p&gt;The pipeline has 4 steps.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Find the card's 4 corners and straighten it (DocAligner)&lt;/li&gt;
&lt;li&gt;Find the text lines (PaddleOCR PP-OCRv6 det)&lt;/li&gt;
&lt;li&gt;Read each line (PP-OCRv6 tiny, &lt;strong&gt;this is the one I trained&lt;/strong&gt;)&lt;/li&gt;
&lt;li&gt;Match the text to the KTP layout, fix it against official lists, and check it against the NIK&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The open models were already good at finding the card and the text lines. Reading was the problem. The general PaddleOCR reader got only about half of the KTP lines exactly right, so that's the only part I trained myself. The others I just compressed.&lt;/p&gt;

&lt;p&gt;The result is JSON with 21 fields, and using it is one HTML element.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;script&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"module"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="s2"&gt;"ktp-kit/element"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;ktp-capture&lt;/span&gt; &lt;span class="na"&gt;base&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/ktp-kit/"&lt;/span&gt; &lt;span class="na"&gt;lang&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"en"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/ktp-capture&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
  &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"ktp-capture"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"ktp-result"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;detail&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Synthetic data
&lt;/h2&gt;

&lt;p&gt;Since I can't use real KTP photos and data, the only other way was collecting cards with consent, and that takes way too much time and effort. So synthetic data it is.&lt;/p&gt;

&lt;p&gt;I wrote a generator that draws single KTP text lines, like labels, names, addresses and NIKs, in KTP fonts and layout. Then it degrades them on purpose so they look like phone photos, with blur, glare, fading, tilt and JPEG artifacts. Names are put together from common name parts, made-up syllables and random letters, so the model learns letters instead of memorizing names. The NIKs use sequence numbers no real person has.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fhpdfkj1vgsdfe5dingmu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fhpdfkj1vgsdfe5dingmu.png" alt="Generated KTP lines and the text the model should read" width="799" height="622"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Lines from the public ktp-kit KTP line benchmark (CC BY 4.0). Blank strips are there so the model learns to read nothing.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;My first version was too clean, and the generated lines were too far from real printed cards. So I looked closely at my own KTP. The values are printed bolder than the labels, the letters are squeezed together, and the ink has tiny gaps in the strokes. I added all three to the generator, and that version is the one I shipped.&lt;/p&gt;

&lt;p&gt;I also tried training more layers of the model. It got worse. The model got better at my fake lines and worse at real print. The real limit was how realistic the data was, not the model's size.&lt;/p&gt;

&lt;h2&gt;
  
  
  Training
&lt;/h2&gt;

&lt;p&gt;I didn't train from scratch. I started from PaddleOCR's PP-OCRv6 tiny reader, which already knows how to read text in general.&lt;/p&gt;

&lt;p&gt;The original model can output 6,906 different characters, because it covers Chinese too. A KTP only uses 46 (A to Z, 0 to 9 and a few symbols). So I cut the output down to those 46 plus one "blank", and kept the pretrained weights for them. Fewer characters means fewer ways to be wrong, and a smaller model, about 0.55M parameters.&lt;/p&gt;

&lt;p&gt;Then I fine-tuned it on the generated lines, on CPU, about an hour per run.&lt;/p&gt;

&lt;h2&gt;
  
  
  Making it fit in the browser
&lt;/h2&gt;

&lt;p&gt;I wanted the whole thing small enough that a phone on mobile data doesn't feel it. When I started, the download was 7.7 MB. Here's what got it under 5.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;int8 weights.&lt;/strong&gt; All three models store their weights as 8-bit integers instead of 32-bit floats. My reader didn't lose any accuracy. I also tried 4-bit on the line finder, but it started missing text, so it stayed at 8-bit.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A smaller ONNX runtime.&lt;/strong&gt; The stock onnxruntime-web WebAssembly file is 11.25 MB. It can run almost any model, but mine only need a few operators. onnxruntime can be built with only the operators you list, so I built it from source with just mine. It came out at 3.75 MB, and 0.87 MB after compression.&lt;/p&gt;

&lt;p&gt;The build wasn't smooth. CMake 4 refused some of the old dependencies, so I went back to CMake 3.31. Then building with 10 parallel jobs ran out of memory on my 16GB laptop, and 4 jobs worked.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Brotli.&lt;/strong&gt; Every file is pre-compressed with brotli, so the download size is the same on any host.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Part&lt;/th&gt;
&lt;th&gt;Download&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Runtime&lt;/td&gt;
&lt;td&gt;0.87 MB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Line finder&lt;/td&gt;
&lt;td&gt;1.71 MB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Card corners&lt;/td&gt;
&lt;td&gt;1.14 MB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;My reader&lt;/td&gt;
&lt;td&gt;0.56 MB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Region list&lt;/td&gt;
&lt;td&gt;0.53 MB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Total&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;about 4.9 MB&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;After the first visit everything stays in the browser's cache, so it works offline.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Speed.&lt;/strong&gt; WebAssembly can use several CPU threads, but only when the page sends two headers (COOP and COEP). With them a read is about 3x faster, around 2 to 4 seconds per card on a mid-range phone.&lt;/p&gt;

&lt;h2&gt;
  
  
  Results
&lt;/h2&gt;

&lt;p&gt;I tested on 2,400 generated lines that were never used for training or for picking the model. The data and scripts are in the repo, so anyone can rerun it.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Reader&lt;/th&gt;
&lt;th&gt;NIK lines&lt;/th&gt;
&lt;th&gt;All text lines&lt;/th&gt;
&lt;th&gt;Blank strips&lt;/th&gt;
&lt;th&gt;Size&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Mine&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;90.8%&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;81.5%&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;97.0%&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;0.7 MB&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;PP-OCRv6 small&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;91.6%&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;51.4%&lt;/td&gt;
&lt;td&gt;70.5%&lt;/td&gt;
&lt;td&gt;21.2 MB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;PP-OCRv6 tiny (where I started)&lt;/td&gt;
&lt;td&gt;87.8%&lt;/td&gt;
&lt;td&gt;48.7%&lt;/td&gt;
&lt;td&gt;71.1%&lt;/td&gt;
&lt;td&gt;4.5 MB&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;On the NIK the general models are just as good, even a bit better. The difference is on names, addresses and other words, and on not "reading" text into the card's background pattern. That's the blank strips column.&lt;/p&gt;

&lt;p&gt;But to be honest, these lines come from the same kind of generator my model learned from, so of course it does well here. I don't have real-card numbers I can publish yet. If you try it on your own card, I'd love to hear how it goes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Limits
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Names are the weakest field. The result has a &lt;code&gt;perlu_dicek&lt;/code&gt; ("needs checking") list that flags fields the model was unsure about, so your form can ask the user to look again.&lt;/li&gt;
&lt;li&gt;Laptop webcams are usually too blurry. Phones work much better.&lt;/li&gt;
&lt;li&gt;The generator itself isn't open source, only the trained model and the benchmark.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Update (v0.4.2)
&lt;/h2&gt;

&lt;p&gt;Since I wrote this post, I switched the text reader base from PP-OCRv6 tiny to PP-OCRv6 small (still int8, still trained only on synthetic lines). The trade-off is a larger download, about 7.1 MB total (the reader is 3.2 MB raw, 2.75 MB brotli), up from 4.9 MB.&lt;/p&gt;

&lt;p&gt;On the same 2,400-line synthetic benchmark, that brought exact match up to &lt;strong&gt;96.2% on NIK lines&lt;/strong&gt; (now ahead of stock PP-OCRv6 small at 91.6%), &lt;strong&gt;85.0% on all text lines&lt;/strong&gt;, and &lt;strong&gt;98.8% on blank strips&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;I also added a Node CLI (&lt;code&gt;npx ktp-kit read photos/*.jpg&lt;/code&gt;), a standalone &lt;a href="https://ktp-kit.khusyasy.my.id/nik" rel="noopener noreferrer"&gt;offline NIK checker&lt;/a&gt; that only loads the Kemendagri region table without ONNX Runtime, and an Indonesian &lt;a href="https://ktp-kit.khusyasy.my.id/docs/ocr-ktp-javascript" rel="noopener noreferrer"&gt;JavaScript KTP OCR guide and comparison&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try it
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://ktp-kit.khusyasy.my.id/en" rel="noopener noreferrer"&gt;Live demo&lt;/a&gt; (no sign-up, &lt;a href="https://ktp-kit.khusyasy.my.id/" rel="noopener noreferrer"&gt;Bahasa Indonesia&lt;/a&gt;) and &lt;a href="https://ktp-kit.khusyasy.my.id/en/docs" rel="noopener noreferrer"&gt;docs&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://ktp-kit.khusyasy.my.id/nik" rel="noopener noreferrer"&gt;Offline NIK checker&lt;/a&gt; and &lt;a href="https://ktp-kit.khusyasy.my.id/docs/ocr-ktp-javascript" rel="noopener noreferrer"&gt;KTP OCR guide in Indonesian&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.npmjs.com/package/ktp-kit" rel="noopener noreferrer"&gt;&lt;code&gt;npm install ktp-kit&lt;/code&gt;&lt;/a&gt;, with React/Vue wrappers and a Node CLI&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/Khusyasy/ktp-kit" rel="noopener noreferrer"&gt;GitHub repo and benchmark&lt;/a&gt;, Apache-2.0, free for commercial use&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is my first time building a system like this, so if you know a better way or spot something wrong, please let me know in the comments!&lt;/p&gt;

</description>
      <category>machinelearning</category>
      <category>javascript</category>
      <category>webassembly</category>
      <category>opensource</category>
    </item>
    <item>
      <title>Local LLM Model on Intel Iris Xe using Ollama</title>
      <dc:creator>Luthfi Khusyasy</dc:creator>
      <pubDate>Mon, 11 May 2026 08:08:05 +0000</pubDate>
      <link>https://dev.to/khusyasy/local-llm-model-on-intel-iris-xe-using-ollama-4hmn</link>
      <guid>https://dev.to/khusyasy/local-llm-model-on-intel-iris-xe-using-ollama-4hmn</guid>
      <description>&lt;p&gt;I have been wanting to run local LLMs, but I only have Intel Iris XE GPU and most sources out there talking about using the newest and the best like RTX 4090 or something :/&lt;/p&gt;

&lt;p&gt;It turns out its not that hard and here is my little journey:&lt;/p&gt;

&lt;h2&gt;
  
  
  Setup
&lt;/h2&gt;

&lt;p&gt;I will be sharing my experience using the environment below, if its not complete please forgive me and add your info on the comments please :3&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Windows 11 and PowerShell 7&lt;/li&gt;
&lt;li&gt;Python 3.11 with &lt;code&gt;uv&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Laptop with 16GB RAM&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Install &lt;code&gt;ipex-llm[cpp]&lt;/code&gt; and Ollama
&lt;/h3&gt;

&lt;p&gt;This is the specific build of &lt;a href="https://pypi.org/project/ipex-llm/" rel="noopener noreferrer"&gt;ipex-llm&lt;/a&gt; that is including the Intel-optimized C++ binaries. It allows Ollama's core to communicate with Iris Xe GPU via the SYCL backend. Make sure to add [cpp] because if not its just the standard library.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="n"&gt;mkdir&lt;/span&gt; &lt;span class="n"&gt;intel&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;ollama&lt;/span&gt;
&lt;span class="n"&gt;cd&lt;/span&gt; &lt;span class="n"&gt;intel&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;ollama&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="n"&gt;uv&lt;/span&gt; &lt;span class="n"&gt;venv&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="n"&gt;python&lt;/span&gt; &lt;span class="mf"&gt;3.11&lt;/span&gt;
&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;\&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;venv&lt;/span&gt;\&lt;span class="nc"&gt;Scripts&lt;/span&gt;\&lt;span class="nc"&gt;Activate&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ps1&lt;/span&gt;
&lt;span class="n"&gt;uv&lt;/span&gt; &lt;span class="n"&gt;pip&lt;/span&gt; &lt;span class="n"&gt;install&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="n"&gt;pre&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="n"&gt;upgrade&lt;/span&gt; &lt;span class="n"&gt;ipex&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;llm&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;cpp&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then run the init script&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="p"&gt;.&lt;/span&gt;\&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;venv&lt;/span&gt;\&lt;span class="nc"&gt;Scripts&lt;/span&gt;\&lt;span class="n"&gt;init&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;ollama&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;bat&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  DLLs Injection
&lt;/h3&gt;

&lt;p&gt;When I tried to run Ollama, I got this error &lt;code&gt;svml_dispmd.dll not found&lt;/code&gt; and a bunch of other dll not found error.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft4eej94y5zw1xob1tp74.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft4eej94y5zw1xob1tp74.png" alt=" " width="591" height="247"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The Intel runtimes should be already installed bundled with the &lt;code&gt;ipex-llm[cpp]&lt;/code&gt;. So we just need to add the DLLs to our env. Here is the short script I used to inject those DLLs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$IntelPaths&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Get&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;ChildItem&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Path&lt;/span&gt; &lt;span class="s2"&gt;".\.venv"&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="k"&gt;Filter&lt;/span&gt; &lt;span class="s2"&gt;"*.dll"&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Recurse&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; 
              &lt;span class="nc"&gt;Select&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Object&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;ExpandProperty&lt;/span&gt; &lt;span class="nc"&gt;DirectoryName&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Unique&lt;/span&gt;
&lt;span class="nv"&gt;$env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nc"&gt;Path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$IntelPaths&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;join&lt;/span&gt; &lt;span class="s2"&gt;";"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s2"&gt;";"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nv"&gt;$env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nc"&gt;Path&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Graphics Driver
&lt;/h3&gt;

&lt;p&gt;After that, the Ollama launched but when I try to run any model it doesnt work. I got error &lt;code&gt;unsupported SPIR-V version number 'unknown (66560)'&lt;/code&gt;. This is because we need at least the driver that have SPIR-V 1.4 version, but my graphics driver is only SPIR-V 1.3.&lt;/p&gt;

&lt;p&gt;To fix it I updated the graphics driver to the latest Intel Arc &amp;amp; Iris Xe Graphics Drivers (31.0.101.xxxx or newer) using the &lt;a href="https://www.intel.com/content/www/us/en/support/intel-driver-support-assistant.html" rel="noopener noreferrer"&gt;Official Updater&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Run Ollama
&lt;/h2&gt;

&lt;p&gt;To run Ollama itself we need to prepare some environment variables. I used this script to do it. I also added the &lt;code&gt;.venv&lt;/code&gt; activation and DLLs injection so it would be easier to run.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;set_env.ps1&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$null&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;eq&lt;/span&gt; &lt;span class="nv"&gt;$env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="no"&gt;VIRTUAL_ENV&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;\&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;venv&lt;/span&gt;\&lt;span class="nc"&gt;Scripts&lt;/span&gt;\&lt;span class="nc"&gt;Activate&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ps1&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nv"&gt;$env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nc"&gt;Path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Get&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;ChildItem&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Path&lt;/span&gt; &lt;span class="s2"&gt;".\.venv"&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="k"&gt;Filter&lt;/span&gt; &lt;span class="s2"&gt;"*.dll"&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Recurse&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nc"&gt;Select&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Object&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;ExpandProperty&lt;/span&gt; &lt;span class="nc"&gt;DirectoryName&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Unique&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;join&lt;/span&gt; &lt;span class="s2"&gt;";"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s2"&gt;";"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nv"&gt;$env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nc"&gt;Path&lt;/span&gt;

&lt;span class="nv"&gt;$env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="no"&gt;SYCL_DEVICE_FILTER&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"level_zero:gpu"&lt;/span&gt;
&lt;span class="nv"&gt;$env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="no"&gt;ONEAPI_DEVICE_SELECTOR&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"level_zero:0"&lt;/span&gt;
&lt;span class="nv"&gt;$env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="no"&gt;ZES_ENABLE_SYSMAN&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"1"&lt;/span&gt;
&lt;span class="nv"&gt;$env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="no"&gt;OLLAMA_INTEL_GPU&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"true"&lt;/span&gt;
&lt;span class="nv"&gt;$env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="no"&gt;OLLAMA_NUM_GPU&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"999"&lt;/span&gt;
&lt;span class="nv"&gt;$env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="no"&gt;OLLAMA_CONTEXT_LENGTH&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"8192"&lt;/span&gt; &lt;span class="c1"&gt;# for IPEX-LLM&lt;/span&gt;
&lt;span class="nv"&gt;$env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="no"&gt;OLLAMA_NUM_CTX&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"8192"&lt;/span&gt;        &lt;span class="c1"&gt;# for Ollama Server&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;start_ollama.ps1&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;\&lt;span class="n"&gt;set_env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ps1&lt;/span&gt;
&lt;span class="nc"&gt;Stop&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="k"&gt;Process&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Name&lt;/span&gt; &lt;span class="n"&gt;ollama&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Force&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;ErrorAction&lt;/span&gt; &lt;span class="nc"&gt;SilentlyContinue&lt;/span&gt;
&lt;span class="p"&gt;.&lt;/span&gt;\&lt;span class="n"&gt;ollama&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;exe&lt;/span&gt; &lt;span class="n"&gt;serve&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;. .\set_env.ps1&lt;/code&gt; Remember to add the dot in the beginning so the env stays in your current terminal.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;After the Ollama server is running using &lt;code&gt;.\start_ollama.ps1&lt;/code&gt;, you can just open new terminal and run &lt;code&gt;.\set_env.ps1&lt;/code&gt;, then use Ollama as usual.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="n"&gt;ollama&lt;/span&gt; &lt;span class="n"&gt;run&lt;/span&gt; &lt;span class="n"&gt;phi3&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;mini&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Results
&lt;/h2&gt;

&lt;p&gt;With this setup, I tried Phi-3 Mini (3.8B) and it runs with 33/33 layers offloaded to the GPU. Finally I can run LLMs locally &amp;gt;:)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3mihjbffvtx8pgt4qbbg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3mihjbffvtx8pgt4qbbg.png" alt=" " width="800" height="346"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>tutorial</category>
      <category>opensource</category>
      <category>agents</category>
    </item>
    <item>
      <title>Simple auth system using JWT</title>
      <dc:creator>Luthfi Khusyasy</dc:creator>
      <pubDate>Tue, 09 Aug 2022 04:23:00 +0000</pubDate>
      <link>https://dev.to/khusyasy/simple-auth-system-using-jwt-59e5</link>
      <guid>https://dev.to/khusyasy/simple-auth-system-using-jwt-59e5</guid>
      <description>&lt;p&gt;Continuation of the last post, I will try to implement auth system by using JWT (Json Web Token) for my Multiplayer TicTacToe game.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://tictactoe.khusyasy.my.id/" rel="noopener noreferrer"&gt;Live Website&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/Khusyasy/ws-tictactoe" rel="noopener noreferrer"&gt;Source Code&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  What is JWT
&lt;/h2&gt;

&lt;p&gt;JWT is an authorization token created from the backend, passed to the frontend and then the frontend can send this token alongside requests to access protected API routes, it is to make sure that the request from user X is indeed made by user X itself. Usually JWT token is created with expiration time.&lt;/p&gt;

&lt;p&gt;There is a downside here for using JWT, every token that was created and not yet expired can still be used for accessing the protected API routes. Which is usually not what you wanted.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Little disclaimer here: I think JWT itself is actually very simple, but implementing it the right way is the hard part, so if you know a better way or have a correction, please let me know! thanks.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;
  
  
  JWT Revoke Method
&lt;/h2&gt;

&lt;p&gt;So to invalidate and limit the access of the token, from what I have found is mainly 2 methods:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Blacklist/Whitelist the token.&lt;/li&gt;
&lt;li&gt;Use per user secret key for the token.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To be honest I still don't know the pros/cons of those methods, but I'm going to use the second one.&lt;/p&gt;
&lt;h2&gt;
  
  
  Creating User Personal Key
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;note: all of the examples shown are simplified version&lt;br&gt;
&lt;/p&gt;


&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;bcrypt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'bcrypt'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;generatePersonalKey&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;bcrypt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;genSaltSync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;First the personal key, we need to create a function to generate the keys, like random strings, numbers, or anything. But here I created &lt;code&gt;generatePersonalKey()&lt;/code&gt; by using the &lt;a href="https://www.npmjs.com/package/bcrypt" rel="noopener noreferrer"&gt;bcrypt&lt;/a&gt; packages to create a random salt.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;mongoose&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'mongoose'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nc"&gt;UserSchema&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;mongoose&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Schema&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;username&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;personalKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And for example my &lt;code&gt;UserSchema&lt;/code&gt; (&lt;a href="https://www.npmjs.com/package/mongoose" rel="noopener noreferrer"&gt;mongoose&lt;/a&gt;), we just initialize the personalKey when the user is created. And when user logged out we just regenerate the personalKey, this way the tokens before will always be invalid because they used the different key.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating JWT
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;jwt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'jsonwebtoken'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;payload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;username&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'khusyasy'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;token&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
  &lt;span class="n"&gt;jwt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sign&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;personalKey&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;expiresIn&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'1h'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To create the token itself I used &lt;a href="https://www.npmjs.com/package/jsonwebtoken" rel="noopener noreferrer"&gt;jsonwebtoken&lt;/a&gt; packages. It is actually very simple like the example above. After that we set the response cookies with the flag &lt;code&gt;httpOnly&lt;/code&gt; so the token cannot be set/get by using javascript on the browser.&lt;/p&gt;

&lt;h2&gt;
  
  
  Checking Authorization
&lt;/h2&gt;

&lt;p&gt;When I first read about this I'm very confused, how do you know which key to use, if you can't even read the token?&lt;/p&gt;

&lt;p&gt;Well it turns out we can... just by using &lt;code&gt;decode&lt;/code&gt; to read the payload and getting the user personalKey, and then using the personalKey to verify the token itself. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;payload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;jwt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;decode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;token&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findOne&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;username&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;username&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;verified&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;jwt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;verify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;token&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;personalKey&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="c1"&gt;// token is verified&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// token is invalid&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That is all for today, thank you for reading!&lt;/p&gt;

&lt;h3&gt;
  
  
  packages used:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.npmjs.com/package/bcrypt" rel="noopener noreferrer"&gt;bcrypt&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.npmjs.com/package/jsonwebtoken" rel="noopener noreferrer"&gt;jsonwebtoken&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.npmjs.com/package/mongoose" rel="noopener noreferrer"&gt;mongoose&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Flame Chat, a Chat App built using Firebase</title>
      <dc:creator>Luthfi Khusyasy</dc:creator>
      <pubDate>Mon, 08 Aug 2022 07:46:00 +0000</pubDate>
      <link>https://dev.to/khusyasy/flame-chat-a-chat-app-built-using-firebase-39g8</link>
      <guid>https://dev.to/khusyasy/flame-chat-a-chat-app-built-using-firebase-39g8</guid>
      <description>&lt;p&gt;Personal chat app built using React and Firebase!.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://chat.khusyasy.my.id/" rel="noopener noreferrer"&gt;Live Website&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/Khusyasy/flame-chat" rel="noopener noreferrer"&gt;Source Code&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;note: this is an old post (22 June 2021) from my website, posting for archiving purposes&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Features
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Person to person private chat.&lt;/li&gt;
&lt;li&gt;Register and Login using Google Auth.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Objectives
&lt;/h2&gt;

&lt;p&gt;Firebase is a BaaS (Backend as a Service) owned by Google that can help developers quickly develop apps. By using firebase for backend service, I can focus more on the looks and experience or known as UI/UX of the apps. I wanted to learn more about firebase, so I decided to create a Personal Chat App.&lt;/p&gt;

&lt;p&gt;The goal of this project is:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Setup Firebase and Firestore.&lt;/li&gt;
&lt;li&gt;Create UI/UX using React.&lt;/li&gt;
&lt;li&gt;Connect Firebase with React.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  1. Setup Firebase and Firestore.
&lt;/h3&gt;

&lt;p&gt;Because this is the first time I used Firebase, I have to learn it first. Searching through Youtube and reading the documentation.&lt;/p&gt;

&lt;p&gt;The process of creating a Firebase project is actually really simple (thanks Google), it took only a couple hours for me.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Create UI/UX using React.
&lt;/h3&gt;

&lt;p&gt;I decided to try out React Bootstrap, it is just Bootstrap but for React. I am actually a little bit familiar with Bootstrap. This should be easy for me.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl0fv5bewejsdmwyzq46k.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl0fv5bewejsdmwyzq46k.jpg" alt="ui ux of the react app" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I also decided to use React Context for managing some of the state like user auth and messages. That is to prevent passing props too many layers down the children element.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Connect React with Firestore.
&lt;/h3&gt;

&lt;p&gt;This part is basically just using React with API that is provided by Firestore. Firestore handles all CRUD function. Firestore is a NoSQl database more or less like MongoDB.&lt;/p&gt;

&lt;h2&gt;
  
  
  Techonologies used
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;React JS&lt;/li&gt;
&lt;li&gt;React Context&lt;/li&gt;
&lt;li&gt;React Bootstrap&lt;/li&gt;
&lt;li&gt;Firebase&lt;/li&gt;
&lt;li&gt;Firestore&lt;/li&gt;
&lt;li&gt;Google Auth&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Creating a Quiz Game, Koding Kuiz</title>
      <dc:creator>Luthfi Khusyasy</dc:creator>
      <pubDate>Mon, 08 Aug 2022 07:40:00 +0000</pubDate>
      <link>https://dev.to/khusyasy/creating-a-quiz-game-koding-kuiz-535j</link>
      <guid>https://dev.to/khusyasy/creating-a-quiz-game-koding-kuiz-535j</guid>
      <description>&lt;p&gt;A quiz game about programming, coding, and related stuff. You can test your knowledge about the subject while having fun!.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://quiz.khusyasy.my.id/" rel="noopener noreferrer"&gt;Live Website&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/Khusyasy/koding-kuiz" rel="noopener noreferrer"&gt;Source Code&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;note: this is an old post (09 May 2021) from my website, posting for archiving purposes&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Features
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Quiz game with multiple categories and difficulties.&lt;/li&gt;
&lt;li&gt;Scoring system.&lt;/li&gt;
&lt;li&gt;Leaderboard system.&lt;/li&gt;
&lt;li&gt;GitHub OAuth integration.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Objectives
&lt;/h2&gt;

&lt;p&gt;I always wanted to create a quiz game about the stuff that i loved, that is tech and programming, and then the player can see how they rank among the other players.&lt;/p&gt;

&lt;p&gt;So to sum it up, the goal of this project is:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a quiz game.&lt;/li&gt;
&lt;li&gt;Create an account system.&lt;/li&gt;
&lt;li&gt;Create a leaderboard system.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  1. Create a quiz game.
&lt;/h3&gt;

&lt;p&gt;Firstly, I make a quick quiz game prototype using a framework that I'm currently learning (Vue JS), and this prototype is gonna be the very basic requirement for my quiz game, so I can visualize what would be needed for the quiz game.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0e9vdxz4n56ky3o2040r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0e9vdxz4n56ky3o2040r.png" alt="quiz prototype" width="409" height="433"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I actually wanted to create my own API for the questions, but after a while I decided to use a public API, and I found QuizApi, and I have to modify the prototype for a bit so the structure of the quiz is compatible.&lt;/p&gt;

&lt;p&gt;I also decided to keep using Vue JS for this project.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Create an account system.
&lt;/h3&gt;

&lt;p&gt;I'm using GitHub OAuth to save time and my sanity, because by using that, I don't have to deal much about account management and security, GitHub already do that better than me.&lt;/p&gt;

&lt;p&gt;I actually never used GitHub OAuth or any Auth API before, so this is some kind of an amazing new learning experience.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Create a leaderboard system.
&lt;/h3&gt;

&lt;p&gt;I created a Express JS server and configure MongoDB, and all the usual server configuration stuff, this step is pretty straight forward, that is creating an backend for database CRUD and creating API endpoint like what I usually do.&lt;/p&gt;

&lt;h2&gt;
  
  
  Techonologies used
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;MongoDB&lt;/li&gt;
&lt;li&gt;Express JS&lt;/li&gt;
&lt;li&gt;Vue JS&lt;/li&gt;
&lt;li&gt;Vuex&lt;/li&gt;
&lt;li&gt;Node JS&lt;/li&gt;
&lt;li&gt;JWT&lt;/li&gt;
&lt;li&gt;GitHub OAuth&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Making a Link Shortener</title>
      <dc:creator>Luthfi Khusyasy</dc:creator>
      <pubDate>Mon, 08 Aug 2022 07:34:00 +0000</pubDate>
      <link>https://dev.to/khusyasy/making-a-link-shortener-4han</link>
      <guid>https://dev.to/khusyasy/making-a-link-shortener-4han</guid>
      <description>&lt;p&gt;This is a website where you can shorten your link, and make it easier to share with your friends.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://sla.khusyasy.my.id/" rel="noopener noreferrer"&gt;Live Website&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/Khusyasy/shortlink-app" rel="noopener noreferrer"&gt;Source Code&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;note: this is an old post (07 March 2021) from my website, posting for archiving purposes&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Features
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Register and Login to your account.&lt;/li&gt;
&lt;li&gt;Shorten your link in just 1 click.&lt;/li&gt;
&lt;li&gt;View how many times your link has been clicked.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Objectives
&lt;/h3&gt;

&lt;p&gt;I wanted to learn the MERN Stack, so i have to combine what i have learned about React JS and Express JS, i also learn how to do CRUD with MongoDB databases using Mongoose, and using JWT for authentication.&lt;/p&gt;

&lt;h3&gt;
  
  
  Techonologies used
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;MongoDB&lt;/li&gt;
&lt;li&gt;Mongoose&lt;/li&gt;
&lt;li&gt;Express JS&lt;/li&gt;
&lt;li&gt;React JS&lt;/li&gt;
&lt;li&gt;React Router&lt;/li&gt;
&lt;li&gt;Node JS&lt;/li&gt;
&lt;li&gt;JWT&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>programming</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Multiplayer TicTacToe With Websockets</title>
      <dc:creator>Luthfi Khusyasy</dc:creator>
      <pubDate>Mon, 08 Aug 2022 06:12:00 +0000</pubDate>
      <link>https://dev.to/khusyasy/creating-multiplayer-tictactoe-game-3bc3</link>
      <guid>https://dev.to/khusyasy/creating-multiplayer-tictactoe-game-3bc3</guid>
      <description>&lt;p&gt;Recently I'm trying to learn about websockets and I decided why not create a Multiplayer TicTacToe game using websocket.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://tictactoe.khusyasy.my.id/" rel="noopener noreferrer"&gt;Live Website&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/Khusyasy/ws-tictactoe" rel="noopener noreferrer"&gt;Source Code&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;note: this is an old post (30 May 2022) from my website, posting for archiving purposes&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;
  
  
  Objectives
&lt;/h2&gt;

&lt;p&gt;Learning more about websockets and how to implement them in a realtime game application. Basically websockets are a way to connect to a server for back and forth communication, this is very useful for realtime applications especially in multiplayer games. Also often used in client side websites.&lt;/p&gt;

&lt;p&gt;The goal of this project is:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create format for websockets.&lt;/li&gt;
&lt;li&gt;Implement the server.&lt;/li&gt;
&lt;li&gt;Create the game using Vue.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  1. Create format for websockets.
&lt;/h3&gt;

&lt;p&gt;Because I am new to websockets, I am trying to understand the format that will be used to communicate with the server, and to be honest I don't find many resources talking about this, so I am going to try to create my own format.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="s2"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="s2"&gt;"data"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;any&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="n"&gt;that&lt;/span&gt; &lt;span class="n"&gt;is&lt;/span&gt; &lt;span class="n"&gt;needed&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From the type of message, the data will be used to determine what the server or client should do. For example, if the type is "move", the data will be used to determine which player moved, and where.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="s2"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"move"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="s2"&gt;"data"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="s2"&gt;"user"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;"x"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;row&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;"y"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;col&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The message above means that the user has moved to row number x and column number y.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Implement the server.
&lt;/h3&gt;

&lt;p&gt;I used express to create the server, and I used express-ws to create the websocket so that I can easily use websockets just like other HTTP requests endpoint in express, as an simple example, the following code is used to create the websocket server.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;express&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'express'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;express&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;ws&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'express-ws'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ws&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'/'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ws&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;ws&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'message'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s1"&gt;'move'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="c1"&gt;// do something with data&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But for storing Users and Rooms in the server, I used an array... for now. I think it's okay, because I only make this for learning purposes. If I ever need to store more data, I can easily extend this project to use database.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Create the game using Vue.
&lt;/h3&gt;

&lt;p&gt;This part is basically creating a TicTacToe game but using Vue. I tried to use a new ui library called &lt;a href="https://www.naiveui.com/" rel="noopener noreferrer"&gt;Naive UI&lt;/a&gt;, I think it looks nice, but I don't know if it's the best way to use the library.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftgfnq8jg520xzvzooewa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftgfnq8jg520xzvzooewa.png" alt="website login page" width="800" height="819"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdrduezui83ibn9zgk29u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdrduezui83ibn9zgk29u.png" alt="winning at tictactoe" width="800" height="819"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
