(Forgive me if the title is inaccurate to the problem this one is boggling the mind) My application requires that I check a value from the request against the database. For this I created an asynchronous function to query the database:
async function checktoken(){
    return prisma.$exists.invalidtoken({token: "testtoken"}).then(result => {
        return(result)
    })
}
I know that the database call on its own works:
prisma.$exists.invalidtoken({token: "testtoken"}).then(result => {
    console.log(result) // returns true 
})
In the function that fires at every request I try and call checktoken():
async function getUser(token){
    var promise = await checktoken()
    var result = promise 
    console.log(result) //undefined
};
Amending the function to include an explicit call to the database works but only when var promise = await checktoken() is defined before it:
async function getUser(token){
    var promise = await checktoken() //When this is removed result1 is undefinded
    await prisma.$exists.invalidtoken({token: "testtoken"}).then(result1 => {
        console.log("inside db call: "+result1) // true
    })
};
I think I have a fundamental misunderstanding of async/await but I am not sure exactly what I am missing.
EDIT: I have updated my approach taking the advice I received and it still does not work. I am beginning to think my ORM is doing something weird:
async function test(token) {
    const status = await prisma.$exists.invalidtoken({ token: token });
    console.log(status);
    return status;
}
test("123") //logs false (as it should)
async function getUser(token){
    var status = await test(token) //logs undefined
    console.log(status) //logs undefined
};



thencallback is a function in itself, so thereturnkeyword would return the callback rather than thegetUserfunction. Wrap it in a promise and resolve it. Or as mentioned by @JamiesonRhyne,async/awaitwithout thethencallback will work equally well..then(result => { return result })demonstrates lack of understanding