feat: auth functions

This commit is contained in:
Adrian Castro
2024-04-15 20:15:43 +02:00
parent 07d313b1fd
commit e8dfb5eaf4
4 changed files with 64 additions and 1 deletions

View File

@@ -27,5 +27,8 @@
"@movie-web/eslint-config/base"
]
},
"prettier": "@movie-web/prettier-config"
"prettier": "@movie-web/prettier-config",
"dependencies": {
"ofetch": "^1.3.4"
}
}

35
packages/api/src/auth.ts Normal file
View File

@@ -0,0 +1,35 @@
import { ofetch } from "ofetch";
export interface SessionResponse {
id: string;
userId: string;
createdAt: string;
accessedAt: string;
device: string;
userAgent: string;
}
export interface LoginResponse {
session: SessionResponse;
token: string;
}
export function getAuthHeaders(token: string): Record<string, string> {
return {
authorization: `Bearer ${token}`,
};
}
export async function accountLogin(
url: string,
id: string,
deviceName: string,
): Promise<LoginResponse> {
return ofetch<LoginResponse>("/auth/login", {
method: "POST",
body: {
id,
device: deviceName,
},
baseURL: url,
});
}

View File

@@ -1 +1,2 @@
export const name = "api";
export * from "./auth";