Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Software Development
Programming
Programming Q&A
DELETE
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="MayoMayn" data-source="post: 434253" data-attributes="member: 71840"><p>I don't get the way you're using async / await.</p><p></p><p>Simply just return the value instead of creating a new Promise using the constructor.</p><p></p><p>[PHP]</p><p>static async create(user) {</p><p> const session = await Database.create(user)</p><p> const token = await JWT.sign(session)</p><p></p><p> return token</p><p>}</p><p>[/PHP]</p><p></p><p>And if you need to reject something inside async / await function simply throw an error.</p><p></p><p>[PHP]</p><p>static async read(session) {</p><p> const jwt = await JWT.validate(session)</p><p> const session = await Database.read(session.id, true)</p><p></p><p> if (!session) throw new Error('invalid session')</p><p></p><p> return { session: session.id, user: session.user } </p><p>}</p><p>[/PHP]</p></blockquote><p></p>
[QUOTE="MayoMayn, post: 434253, member: 71840"] I don't get the way you're using async / await. Simply just return the value instead of creating a new Promise using the constructor. [PHP] static async create(user) { const session = await Database.create(user) const token = await JWT.sign(session) return token } [/PHP] And if you need to reject something inside async / await function simply throw an error. [PHP] static async read(session) { const jwt = await JWT.validate(session) const session = await Database.read(session.id, true) if (!session) throw new Error('invalid session') return { session: session.id, user: session.user } } [/PHP] [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Software Development
Programming
Programming Q&A
DELETE
Top