import * as db from '../db' ; import * as api from '../api' ; export async function login ( login ) { const ownerRes = await api . postLogin ( login ) ; let owner = await db . getOwner ( ownerRes . id ) ; if ( ! owner ) { owner = await db . addOwner ( ownerRes ) ; } if ( owner . publicKey && ! ownerRes . publicKey ) { await api . patchOwner ( { publicKey : owner . publicKey } ) ; } if ( ! owner . publicKey && ownerRes . publicKey ) { owner . publicKey = ownerRes . publicKey ; owner = await db . updateOwner ( owner ) ; } return owner ; }