<?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"><channel><title><![CDATA[Regster API Function.]]></title><description><![CDATA[<p dir="auto">This function I wrote does not always give me the token. <strong>(It does work sometimes)</strong><br />
This is the message I receive:</p>
<p dir="auto"><strong>"errorMessage": "Cannot read property '0' of undefined",</strong></p>
<p dir="auto">This is the fusction :</p>
<pre><code>const cloudbackend = require('appdrag-cloudbackend');
cloudbackend.init(process.env.APIKEY, process.env.APPID);
const bcrypt = require('bcrypt');
const uuid = require('uuid');
exports.handler = async(event, context, callback) =&gt; {
  
  let name = event["POST"]["name"];
    let nickname = event["POST"]["nickname"];
    let email = event["POST"]["email"];
    let password = event["POST"]["password"];
    let hachPassword = bcrypt.hashSync(password, 10);

    //Check email does not exists. 
    let finedEmai = `SELECT email FROM users WHERE email = '${email}' `

    await cloudbackend.sqlSelect(finedEmai).then(async res =&gt; {

        let result = JSON.parse(res);

        if (result.Table == null) {

            // Add user to DB.

            let sql = `INSERT INTO users (name, nickname, email, password, date_joined, token) VALUES ('${name}', '${nickname}', '${email}','${hachPassword}', now() , uuid())`;

            await cloudbackend.sqlExecuteRawQuery(sql).then(async res =&gt; {

                // Get current users token

                let cotentToken = `SELECT token FROM users WHERE id = LAST_INSERT_ID()`

                await cloudbackend.sqlSelect(cotentToken).then(async res =&gt; {

                    let result = await JSON.parse(res);

                    let token = result.Table[0]

                    callback(null, token);
                });

         
            });
        } else {
            callback(null, result.Table[0])
        }
    })
}
</code></pre>
]]></description><link>https://community.appdrag.com/topic/722/regster-api-function</link><generator>RSS for Node</generator><lastBuildDate>Tue, 15 Sep 2026 00:00:23 GMT</lastBuildDate><atom:link href="https://community.appdrag.com/topic/722.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 22 Feb 2021 19:01:33 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Regster API Function. on Wed, 03 Mar 2021 07:33:15 GMT]]></title><description><![CDATA[<p dir="auto"><a href="https://www.npmjs.com/package/appdrag-cloudbackend" rel="nofollow ugc">https://www.npmjs.com/package/appdrag-cloudbackend</a></p>
<p dir="auto">You can JSON.parse(response); and check numberOfAffectedRows.</p>
]]></description><link>https://community.appdrag.com/post/2989</link><guid isPermaLink="true">https://community.appdrag.com/post/2989</guid><dc:creator><![CDATA[Wassim]]></dc:creator><pubDate>Wed, 03 Mar 2021 07:33:15 GMT</pubDate></item><item><title><![CDATA[Reply to Regster API Function. on Tue, 02 Mar 2021 10:15:33 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.appdrag.com/uid/2">@Wassim</a> said in <a href="/post/2938">Regster API Function.</a>:</p>
<blockquote>
<p dir="auto">how many rows have been affected in the return of sqlExecuteRawQuery</p>
</blockquote>
<p dir="auto">how do I check it?</p>
]]></description><link>https://community.appdrag.com/post/2982</link><guid isPermaLink="true">https://community.appdrag.com/post/2982</guid><dc:creator><![CDATA[malky shlomowith]]></dc:creator><pubDate>Tue, 02 Mar 2021 10:15:33 GMT</pubDate></item><item><title><![CDATA[Reply to Regster API Function. on Thu, 25 Feb 2021 07:21:20 GMT]]></title><description><![CDATA[<p dir="auto">you're welcome <img src="https://community.appdrag.com/plugins/nodebb-plugin-emoji/emoji/android/1f64f.png?v=lfk1vimvd74" class="not-responsive emoji emoji-android emoji--pray" title=":pray:" alt="🙏" /> !</p>
]]></description><link>https://community.appdrag.com/post/2952</link><guid isPermaLink="true">https://community.appdrag.com/post/2952</guid><dc:creator><![CDATA[Wassim]]></dc:creator><pubDate>Thu, 25 Feb 2021 07:21:20 GMT</pubDate></item><item><title><![CDATA[Reply to Regster API Function. on Wed, 24 Feb 2021 23:41:16 GMT]]></title><description><![CDATA[<p dir="auto">thanks for your help!</p>
]]></description><link>https://community.appdrag.com/post/2950</link><guid isPermaLink="true">https://community.appdrag.com/post/2950</guid><dc:creator><![CDATA[malky shlomowith]]></dc:creator><pubDate>Wed, 24 Feb 2021 23:41:16 GMT</pubDate></item><item><title><![CDATA[Reply to Regster API Function. on Wed, 24 Feb 2021 07:16:05 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.appdrag.com/uid/665">@malky-shlomowith</a> said in <a href="/post/2944">Regster API Function.</a>:</p>
<blockquote>
<p dir="auto">my-recipe-app-1fe491</p>
</blockquote>
<p dir="auto">It seems that for unique column the length should be smaller, try 150 or 100 instead of 200 for the email. There won't be a single user with an email address that long.</p>
]]></description><link>https://community.appdrag.com/post/2945</link><guid isPermaLink="true">https://community.appdrag.com/post/2945</guid><dc:creator><![CDATA[Wassim]]></dc:creator><pubDate>Wed, 24 Feb 2021 07:16:05 GMT</pubDate></item><item><title><![CDATA[Reply to Regster API Function. on Tue, 23 Feb 2021 23:07:09 GMT]]></title><description><![CDATA[<p dir="auto">Hi!<br />
Thanks for you answer!<br />
I tried setting the email column as unique and this it the error I am getting:</p>
<p dir="auto">Error: Specified key was too long; max key length is 767 bytes</p>
<p dir="auto">{"m_MaxCapacity":2147483647,"Capacity":1768,"m_StringValue":"ALTER TABLE <code>my-recipe-app-1fe491</code>.<code>users</code> CHANGE COLUMN <code>id</code> <code>id</code> int AUTO_INCREMENT COMMENT '::' FIRST ;<br />
ALTER TABLE <code>my-recipe-app-1fe491</code>.<code>users</code> CHANGE COLUMN <code>name</code> <code>name</code> varchar(255) COMMENT '::' AFTER <code>id</code> ;<br />
ALTER TABLE <code>my-recipe-app-1fe491</code>.<code>users</code> CHANGE COLUMN <code>nickname</code> <code>nickname</code> varchar(255) COMMENT '::' AFTER <code>name</code> ;<br />
ALTER TABLE <code>my-recipe-app-1fe491</code>.<code>users</code> ADD UNIQUE INDEX <code>email_UNIQUE</code> (<code>email</code> ASC);<br />
ALTER TABLE <code>my-recipe-app-1fe491</code>.<code>users</code> CHANGE COLUMN <code>email</code> <code>email</code> varchar(200) COMMENT 'email::' AFTER <code>nickname</code> ;<br />
ALTER TABLE <code>my-recipe-app-1fe491</code>.<code>users</code> CHANGE COLUMN <code>password</code> <code>password</code> varchar(255) COMMENT 'password::' AFTER <code>email</code> ;<br />
ALTER TABLE <code>my-recipe-app-1fe491</code>.<code>users</code> CHANGE COLUMN <code>date_joined</code> <code>date_joined</code> date COMMENT '::' AFTER <code>password</code> ;<br />
ALTER TABLE <code>my-recipe-app-1fe491</code>.<code>users</code> CHANGE COLUMN <code>active</code> <code>active</code> int DEFAULT '0' COMMENT '::' AFTER <code>date_joined</code> ;<br />
ALTER TABLE <code>my-recipe-app-1fe491</code>.<code>users</code> CHANGE COLUMN <code>token</code> <code>token</code> varchar(255) COMMENT '::' AFTER <code>active</code> ;<br />
","m_currentThread":0}</p>
]]></description><link>https://community.appdrag.com/post/2944</link><guid isPermaLink="true">https://community.appdrag.com/post/2944</guid><dc:creator><![CDATA[malky shlomowith]]></dc:creator><pubDate>Tue, 23 Feb 2021 23:07:09 GMT</pubDate></item><item><title><![CDATA[Reply to Regster API Function. on Tue, 23 Feb 2021 07:16:15 GMT]]></title><description><![CDATA[<p dir="auto">Hi,<br />
You can simplify the process</p>
<ul>
<li>Set the email column as a unique in the table edition</li>
</ul>
<p dir="auto"><img src="/assets/uploads/files/1614064354108-ba42a61c-bf07-49f7-94a3-ebfeb360cfe3-image.png" alt="ba42a61c-bf07-49f7-94a3-ebfeb360cfe3-image.png" class="img-responsive img-markdown" /></p>
<ul>
<li>Then check how many rows have been affected in the return of sqlExecuteRawQuery</li>
<li>If it's 0 throw an error, if it's 1 select the token of the new user</li>
</ul>
<p dir="auto">By the way avoid nesting async await.. It adds complexity for no reason.</p>
]]></description><link>https://community.appdrag.com/post/2938</link><guid isPermaLink="true">https://community.appdrag.com/post/2938</guid><dc:creator><![CDATA[Wassim]]></dc:creator><pubDate>Tue, 23 Feb 2021 07:16:15 GMT</pubDate></item></channel></rss>