add: auth functionality basics
This commit is contained in:
+18
-34
@@ -1,41 +1,25 @@
|
||||
const BASE_URL = process.env.NEXT_PUBLIC_API_URL || 'https://api.example.com'
|
||||
import { api } from './axiosInstance'
|
||||
|
||||
export async function checkUserExists(phoneNumber: string): Promise<boolean> {
|
||||
const res = phoneNumber === "123";
|
||||
const data = { status: 200, result: { exists: res } }
|
||||
return data.result.exists
|
||||
export const login = async ({ phone, password }: { phone: string; password: string }) => {
|
||||
const res = await api.post('/login', { phone, password })
|
||||
console.log(res);
|
||||
return res.data // { user: { id, name, email, token } }
|
||||
}
|
||||
|
||||
export async function signup(userData: {
|
||||
phoneNumber: string,
|
||||
export const signup = async ({
|
||||
phone,
|
||||
password,
|
||||
}: {
|
||||
phone: string
|
||||
password: string
|
||||
}) {
|
||||
const res = userData.phoneNumber === "123" && userData.password === "123";
|
||||
const data = { sucess: res }
|
||||
return {
|
||||
data,
|
||||
user: {
|
||||
id: '123',
|
||||
name: 'John Doe',
|
||||
number: userData.phoneNumber,
|
||||
token: 'mock-jwt-token',
|
||||
}
|
||||
}
|
||||
}) => {
|
||||
const res = await api.post('/signup', { phone, password })
|
||||
console.log(res);
|
||||
return res.data
|
||||
}
|
||||
|
||||
export async function login(credentials: {
|
||||
phoneNumber: string,
|
||||
password: string
|
||||
}) {
|
||||
const res = credentials.phoneNumber === "1234" && credentials.password === "1234";
|
||||
const data = { sucess: res }
|
||||
return {
|
||||
data,
|
||||
user: {
|
||||
id: '1234',
|
||||
name: 'Foo bar',
|
||||
number: credentials.phoneNumber,
|
||||
token: 'mock-jwt-token',
|
||||
}
|
||||
}
|
||||
export const checkUserExists = async (phone: string) => {
|
||||
const res = await api.get(`/exists/${encodeURIComponent(phone)}`)
|
||||
console.log(res);
|
||||
return res.data.exists as boolean
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
import axios from 'axios'
|
||||
|
||||
export const api = axios.create({
|
||||
baseURL: process.env.NEXT_PUBLIC_API_URL || 'https://api.example.com',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
})
|
||||
Reference in New Issue
Block a user