<?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: Jourdan Laik</title>
    <description>The latest articles on DEV Community by Jourdan Laik (@jourdanlaik).</description>
    <link>https://dev.to/jourdanlaik</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%2F4273671%2Fa9902286-3c9d-449d-8991-6185bff54690.jpg</url>
      <title>DEV Community: Jourdan Laik</title>
      <link>https://dev.to/jourdanlaik</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jourdanlaik"/>
    <language>en</language>
    <item>
      <title>How to add license keys to an Electron app</title>
      <dc:creator>Jourdan Laik</dc:creator>
      <pubDate>Wed, 02 Dec 2026 20:33:58 +0000</pubDate>
      <link>https://dev.to/jourdanlaik/how-to-add-license-keys-to-an-electron-app-4ckl</link>
      <guid>https://dev.to/jourdanlaik/how-to-add-license-keys-to-an-electron-app-4ckl</guid>
      <description>&lt;p&gt;If you sell an Electron app, licensing needs two things: a way to activate a key once, and a check on every launch that still works offline. This post shows both with &lt;code&gt;@keygrant/electron&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;(Disclosure: we build KeyGrant. We made it because a new app usually has no customers yet, and licensing shouldn't cost you anything before you've sold a copy. It's free until your app takes off, with no hidden fees and no revenue share.)&lt;/p&gt;

&lt;h2&gt;
  
  
  What you need
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;A KeyGrant account (free up to 250 active licenses) and a product in the dashboard&lt;/li&gt;
&lt;li&gt;A license key: issue one under &lt;strong&gt;Licenses &amp;gt; Issue a license&lt;/strong&gt;, or create a test license&lt;/li&gt;
&lt;li&gt;Node.js 20 or later. The SDK runs in Electron's main process, not in a renderer.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  1. Install the SDK
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm install @keygrant/electron
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  2. Get your public key
&lt;/h2&gt;

&lt;p&gt;Your app checks each license with your product's public key. Fetch it once and ship it with the app. The request needs no API key:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl https://api.keygrant.dev/v1/products/my-product/pubkey
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;my-product&lt;/code&gt; is your product's API ID, the last part of its page's URL in the dashboard.&lt;/li&gt;
&lt;li&gt;Keep the &lt;code&gt;keys&lt;/code&gt; array from the response. You pass it to the SDK unchanged.&lt;/li&gt;
&lt;li&gt;The dashboard's &lt;strong&gt;Signing key&lt;/strong&gt; tab has a &lt;strong&gt;Copy key set&lt;/strong&gt; button that copies the same thing.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  3. Activate a key
&lt;/h2&gt;

&lt;p&gt;Create one &lt;code&gt;License&lt;/code&gt; for the process, and activate the key your customer enters:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;License&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"@keygrant/electron"&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;license&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;License&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;product&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"my-product"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;apiBaseUrl&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"https://api.keygrant.dev"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;publicJwks&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;PUBLIC_KEYS&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// the keys from step 2&lt;/span&gt;
  &lt;span class="n"&gt;major&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// this build's major version&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;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;license&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;activate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;userEnteredKey&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="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nf"&gt;showActivationError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;error&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;&lt;code&gt;activate&lt;/code&gt; checks the key with KeyGrant, takes one of the key's device seats for this machine, and stores a signed license (a JWT) on the device. When it fails, &lt;code&gt;result.error&lt;/code&gt; says why, such as &lt;code&gt;invalid-key&lt;/code&gt; or &lt;code&gt;limit&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Check the license on every launch
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;checkLicense&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;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;license&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&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;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;state&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s2"&gt;"licensed"&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;state&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s2"&gt;"trial"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// run&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;state&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s2"&gt;"unknown"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// The license file could not be read: keep running and check again shortly.&lt;/span&gt;
    &lt;span class="nb"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;checkLicense&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5_000&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="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="c1"&gt;// "expired" or "invalid": status.reason says why. "unlicensed": no key is stored yet.&lt;/span&gt;
  &lt;span class="nf"&gt;showActivationWindow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;status&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="nf"&gt;checkLicense&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;&lt;code&gt;status()&lt;/code&gt; checks the stored license on the device and usually needs no network. When the license is close to its end, it renews it first, waiting at most 5 seconds for KeyGrant. If KeyGrant can't be reached, your app keeps working until the license runs out.&lt;/p&gt;

&lt;h2&gt;
  
  
  Selling it
&lt;/h2&gt;

&lt;p&gt;Connect your Stripe account in the dashboard and pick the Stripe price for each license model. Each paid checkout then creates a key, with no code on your side. To have KeyGrant email the key to the buyer, choose &lt;strong&gt;KeyGrant sends them&lt;/strong&gt; on the product's &lt;strong&gt;License delivery&lt;/strong&gt; tab.&lt;/p&gt;

&lt;p&gt;Your app's Buy button just opens your Stripe Payment Link:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;shell&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"electron"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;shell&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;openExternal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"https://buy.stripe.com/your-link"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// Once they have the key from the email:&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;license&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;activate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;enteredKey&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;Selling through Paddle instead? Its checkouts create keys the same way: &lt;a href="https://keygrant.dev/docs/getting-started/paddle" rel="noopener noreferrer"&gt;https://keygrant.dev/docs/getting-started/paddle&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Next
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Full quick start: &lt;a href="https://keygrant.dev/docs/getting-started" rel="noopener noreferrer"&gt;https://keygrant.dev/docs/getting-started&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Electron SDK reference: &lt;a href="https://keygrant.dev/docs/sdks/electron" rel="noopener noreferrer"&gt;https://keygrant.dev/docs/sdks/electron&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can ship licensing on day one and pay nothing until you pass 250 active licenses. Questions welcome in the comments.&lt;/p&gt;

</description>
      <category>electron</category>
      <category>javascript</category>
      <category>node</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
