UNPKG

@privy-io/js-sdk-core

Version:

Vanilla JS client for the Privy Auth API

2 lines (1 loc) 1.63 kB
import{PasswordlessInit as e,PasswordlessAuthenticate as t,PasswordlessLink as i,PasswordlessUpdate as s,PasswordlessUnlink as r}from"@privy-io/public-api";import{maybeCreateWalletOnLogin as d}from"./maybeCreateWalletOnLogin.mjs";import"../../utils/getUserEmbeddedEthereumWallet.mjs";import"../../utils/getAllUserEmbeddedEthereumWallets.mjs";import"../../utils/embedded-wallets.mjs";import"../../utils/getUserEmbeddedSolanaWallet.mjs";import"../../utils/getAllUserEmbeddedSolanaWallets.mjs";import"../../utils/shouldCreateEmbeddedEthWallet.mjs";import"../../utils/shouldCreateEmbeddedSolWallet.mjs";class a{async sendCode(t,i){return this._privyInternal.fetch(e,{body:{email:t,token:i}})}async loginWithCode(e,i,s,r){let a=await this._privyInternal.fetch(t,{body:{email:e,code:i,mode:s}});await this._privyInternal.session.updateWithTokensResponse(a);let l=await d(this._embedded,a,r?.embedded);return this._privyInternal.callbacks?.setUser?.(l.user),l}async linkWithCode(e,t){await this._privyInternal.fetch(i,{body:{email:e,code:t}});let s=await this._privyInternal.refreshSession();return{user:s.user,identity_token:s.identity_token}}async updateEmail({oldEmailAddress:e,newEmailAddress:t,code:i}){await this._privyInternal.fetch(s,{body:{oldAddress:e,newAddress:t,code:i}});let r=await this._privyInternal.refreshSession();return{user:r.user,identity_token:r.identity_token}}async unlink(e){await this._privyInternal.fetch(r,{body:{address:e}});let t=await this._privyInternal.refreshSession();return{user:t.user,identity_token:t.identity_token}}constructor(e,t){this._privyInternal=e,this._embedded=t}}export{a as default};