@instantdb/core
Version:
Instant's core local abstraction
83 lines • 2.79 kB
JavaScript
import { jsonFetch } from './utils/fetch.js';
export function sendMagicCode({ apiURI, appId, email, }) {
return jsonFetch(`${apiURI}/runtime/auth/send_magic_code`, {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ 'app-id': appId, email }),
});
}
export async function verifyMagicCode({ apiURI, appId, email, code, refreshToken, }) {
const res = await jsonFetch(`${apiURI}/runtime/auth/verify_magic_code`, {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({
'app-id': appId,
email,
code,
...(refreshToken ? { 'refresh-token': refreshToken } : {}),
}),
});
return res;
}
export async function verifyRefreshToken({ apiURI, appId, refreshToken, }) {
const res = await jsonFetch(`${apiURI}/runtime/auth/verify_refresh_token`, {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({
'app-id': appId,
'refresh-token': refreshToken,
}),
});
return res;
}
export async function signInAsGuest({ apiURI, appId, }) {
const res = await jsonFetch(`${apiURI}/runtime/auth/sign_in_guest`, {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({
'app-id': appId,
}),
});
return res;
}
export async function exchangeCodeForToken({ apiURI, appId, code, codeVerifier, refreshToken, }) {
const res = await jsonFetch(`${apiURI}/runtime/oauth/token`, {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({
app_id: appId,
code: code,
code_verifier: codeVerifier,
refresh_token: refreshToken,
}),
});
return res;
}
export async function signInWithIdToken({ apiURI, appId, nonce, idToken, clientName, refreshToken, }) {
const res = await jsonFetch(`${apiURI}/runtime/oauth/id_token`, {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({
app_id: appId,
nonce,
id_token: idToken,
client_name: clientName,
refresh_token: refreshToken,
}),
});
return res;
}
export async function signOut({ apiURI, appId, refreshToken, }) {
const res = await jsonFetch(`${apiURI}/runtime/signout`, {
method: 'POST',
headers: {
'content-type': 'application/json',
},
body: JSON.stringify({
app_id: appId,
refresh_token: refreshToken,
}),
});
return res;
}
//# sourceMappingURL=authAPI.js.map