devv-code-backend
Version:
Devv Code Backend SDK - like Supabase for Devv Code
51 lines (50 loc) • 1.72 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.DevvAuth = void 0;
class DevvAuth {
constructor() {
this.baseURL = 'https://api-dev.copilothub.ai/api/';
}
async sendOTP(email) {
const response = await fetch(`${this.baseURL}v1/project-auth/send-verification-email`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
credentials: 'include',
body: JSON.stringify({ email })
});
if (!response.ok) {
const error = await response.json();
throw new Error(error.error || 'Failed to send OTP');
}
}
async verifyOTP(email, verificationCode) {
const response = await fetch(`${this.baseURL}v1/project-auth/login`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
credentials: 'include',
body: JSON.stringify({
authType: 8,
email,
verificationCode
})
});
if (!response.ok) {
const error = await response.json();
throw new Error(error.error || 'Invalid verification code');
}
const data = await response.json();
return data;
}
async logout() {
const response = await fetch(`${this.baseURL}v1/project-auth/logout`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
credentials: 'include'
});
if (!response.ok) {
const error = await response.json();
throw new Error(error.error || 'Logout failed');
}
}
}
exports.DevvAuth = DevvAuth;