mirror of
https://github.com/movie-web/native-app.git
synced 2025-09-13 10:23:24 +00:00
feat: auth functions
This commit is contained in:
@@ -27,5 +27,8 @@
|
|||||||
"@movie-web/eslint-config/base"
|
"@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
35
packages/api/src/auth.ts
Normal 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,
|
||||||
|
});
|
||||||
|
}
|
@@ -1 +1,2 @@
|
|||||||
export const name = "api";
|
export const name = "api";
|
||||||
|
export * from "./auth";
|
||||||
|
24
pnpm-lock.yaml
generated
24
pnpm-lock.yaml
generated
@@ -242,6 +242,10 @@ importers:
|
|||||||
version: 5.4.3
|
version: 5.4.3
|
||||||
|
|
||||||
packages/api:
|
packages/api:
|
||||||
|
dependencies:
|
||||||
|
ofetch:
|
||||||
|
specifier: ^1.3.4
|
||||||
|
version: 1.3.4
|
||||||
devDependencies:
|
devDependencies:
|
||||||
'@movie-web/eslint-config':
|
'@movie-web/eslint-config':
|
||||||
specifier: workspace:^0.2.0
|
specifier: workspace:^0.2.0
|
||||||
@@ -7077,6 +7081,10 @@ packages:
|
|||||||
minimalistic-assert: 1.0.1
|
minimalistic-assert: 1.0.1
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
|
/destr@2.0.3:
|
||||||
|
resolution: {integrity: sha512-2N3BOUU4gYMpTP24s5rF5iP7BDr7uNTCs4ozw3kf/eKfvWSIu93GEBi5m427YoyJoeOzQ5smuu4nNAPGb8idSQ==}
|
||||||
|
dev: false
|
||||||
|
|
||||||
/destroy@1.2.0:
|
/destroy@1.2.0:
|
||||||
resolution: {integrity: sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==}
|
resolution: {integrity: sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==}
|
||||||
engines: {node: '>= 0.8', npm: 1.2.8000 || >= 1.4.16}
|
engines: {node: '>= 0.8', npm: 1.2.8000 || >= 1.4.16}
|
||||||
@@ -10503,6 +10511,10 @@ packages:
|
|||||||
engines: {node: '>=10.5.0'}
|
engines: {node: '>=10.5.0'}
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
|
/node-fetch-native@1.6.4:
|
||||||
|
resolution: {integrity: sha512-IhOigYzAKHd244OC0JIMIUrjzctirCmPkaIfhDeGcEETWof5zKYUW7e7MYvChGWh/4CJeXEgsRyGzuF334rOOQ==}
|
||||||
|
dev: false
|
||||||
|
|
||||||
/node-fetch@2.7.0:
|
/node-fetch@2.7.0:
|
||||||
resolution: {integrity: sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==}
|
resolution: {integrity: sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==}
|
||||||
engines: {node: 4.x || >=6.0.0}
|
engines: {node: 4.x || >=6.0.0}
|
||||||
@@ -10681,6 +10693,14 @@ packages:
|
|||||||
es-abstract: 1.22.3
|
es-abstract: 1.22.3
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
|
/ofetch@1.3.4:
|
||||||
|
resolution: {integrity: sha512-KLIET85ik3vhEfS+3fDlc/BAZiAp+43QEC/yCo5zkNoY2YaKvNkOaFr/6wCFgFH1kuYQM5pMNi0Tg8koiIemtw==}
|
||||||
|
dependencies:
|
||||||
|
destr: 2.0.3
|
||||||
|
node-fetch-native: 1.6.4
|
||||||
|
ufo: 1.5.3
|
||||||
|
dev: false
|
||||||
|
|
||||||
/on-finished@2.3.0:
|
/on-finished@2.3.0:
|
||||||
resolution: {integrity: sha512-ikqdkGAAyf/X/gPhXGvfgAytDZtDbr+bkNUJ0N9h5MI/dmdgCs3l6hoHrcUv41sRKew3jIwrp4qQDXiK99Utww==}
|
resolution: {integrity: sha512-ikqdkGAAyf/X/gPhXGvfgAytDZtDbr+bkNUJ0N9h5MI/dmdgCs3l6hoHrcUv41sRKew3jIwrp4qQDXiK99Utww==}
|
||||||
engines: {node: '>= 0.8'}
|
engines: {node: '>= 0.8'}
|
||||||
@@ -13328,6 +13348,10 @@ packages:
|
|||||||
resolution: {integrity: sha512-8Y75pvTYkLJW2hWQHXxoqRgV7qb9B+9vFEtidML+7koHUFapnVJAZ6cKs+Qjz5Aw3aZWHMC6u0wJE3At+nSGwA==}
|
resolution: {integrity: sha512-8Y75pvTYkLJW2hWQHXxoqRgV7qb9B+9vFEtidML+7koHUFapnVJAZ6cKs+Qjz5Aw3aZWHMC6u0wJE3At+nSGwA==}
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
|
/ufo@1.5.3:
|
||||||
|
resolution: {integrity: sha512-Y7HYmWaFwPUmkoQCUIAYpKqkOf+SbVj/2fJJZ4RJMCfZp0rTGwRbzQD+HghfnhKOjL9E01okqz+ncJskGYfBNw==}
|
||||||
|
dev: false
|
||||||
|
|
||||||
/uglify-js@3.17.4:
|
/uglify-js@3.17.4:
|
||||||
resolution: {integrity: sha512-T9q82TJI9e/C1TAxYvfb16xO120tMVFZrGA3f9/P4424DNu6ypK103y0GPFVa17yotwSyZW5iYXgjYHkGrJW/g==}
|
resolution: {integrity: sha512-T9q82TJI9e/C1TAxYvfb16xO120tMVFZrGA3f9/P4424DNu6ypK103y0GPFVa17yotwSyZW5iYXgjYHkGrJW/g==}
|
||||||
engines: {node: '>=0.8.0'}
|
engines: {node: '>=0.8.0'}
|
||||||
|
Reference in New Issue
Block a user