@inertiapixel/nextjs-auth
Version:
A reusable Next.js authentication package supporting credentials, OTP, and OAuth login.
18 lines (17 loc) • 528 B
JavaScript
// src/login/otpLogin.ts
import { ApiClient } from '../apiClient';
import { parseToken } from '../tokenUtils';
const api = new ApiClient();
export const loginWithOTP = async (url, payload) => {
const data = await api.post(url, payload);
if (!data.accessToken) {
throw new Error('Access token missing in response');
}
const user = parseToken(data.accessToken);
return {
isAuthenticated: true,
accessToken: data.accessToken,
message: data.message ?? '',
user,
};
};