mirror of
https://github.com/lucaspalomodevelop/auth-tools.git
synced 2026-03-13 06:09:37 +00:00
updated protocol
This commit is contained in:
parent
0ec6d7f124
commit
5ad713bb75
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@auth-tools/base",
|
||||
"version": "0.0.1-alpha.2",
|
||||
"version": "0.0.1-alpha.4",
|
||||
"description": "A structured authentication protocol for Javascript. (base)",
|
||||
"main": "dist/index.js",
|
||||
"repository": "https://github.com/auth-tools/auth-tools",
|
||||
|
||||
@ -19,14 +19,13 @@ type AuthResponseBuilder<
|
||||
InterceptCode extends number = 0,
|
||||
AuthMessage = AuthMessages[`${Method}_${StatusCode}`]
|
||||
> = {
|
||||
auth: {
|
||||
error: StatusCode extends 0 ? false : true;
|
||||
errorType: Method extends "server" ? "server" : "method";
|
||||
message: AuthMessage;
|
||||
codes: {
|
||||
status: StatusCode;
|
||||
intercept: InterceptCode;
|
||||
};
|
||||
error: StatusCode extends 0 ? false : true;
|
||||
intercepted: InterceptCode extends 0 ? false : true,
|
||||
errorType: Method extends "server" ? "server" : "method";
|
||||
message: AuthMessage;
|
||||
codes: {
|
||||
status: StatusCode;
|
||||
intercept: InterceptCode;
|
||||
};
|
||||
data: ResponseData;
|
||||
};
|
||||
|
||||
@ -1,6 +1,10 @@
|
||||
import { UserData } from "@auth-tools/base";
|
||||
import { Logger } from "@auth-tools/logger";
|
||||
import { AuthServer, AuthServerConfig } from "@auth-tools/server";
|
||||
import {
|
||||
AuthServer,
|
||||
AuthServerConfig,
|
||||
AuthServerMethod,
|
||||
} from "@auth-tools/server";
|
||||
|
||||
const Users: UserData[] = [];
|
||||
const Tokens: string[] = [];
|
||||
@ -70,3 +74,12 @@ authServer.use("genId", ({}) => {
|
||||
const id = Users.length.toString();
|
||||
return { serverError: false, id };
|
||||
});
|
||||
(async () => {
|
||||
console.log(
|
||||
await (authServer.methods.register as AuthServerMethod<"register">)({
|
||||
email: "as@as",
|
||||
username: "as",
|
||||
password: "sd",
|
||||
})
|
||||
);
|
||||
})();
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@auth-tools/server",
|
||||
"version": "0.0.1-alpha.1",
|
||||
"version": "0.0.1-alpha.2",
|
||||
"description": "A structured authentication protocol for Javascript. (server)",
|
||||
"main": "dist/index.js",
|
||||
"repository": "https://github.com/auth-tools/auth-tools",
|
||||
@ -15,7 +15,7 @@
|
||||
"remove": "npm run build:remove && rimraf node_modules yarn.lock package-lock.json pnpm-lock.yaml"
|
||||
},
|
||||
"dependencies": {
|
||||
"@auth-tools/base": "^0.0.1-alpha.2",
|
||||
"@auth-tools/base": "^0.0.1-alpha.4",
|
||||
"jsonwebtoken": "^9.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@ -82,12 +82,11 @@ export function createCheck(
|
||||
);
|
||||
|
||||
return {
|
||||
auth: {
|
||||
error: false,
|
||||
errorType: "method",
|
||||
message: "Check successful.",
|
||||
codes: { status: 0, intercept: 0 },
|
||||
},
|
||||
error: false,
|
||||
intercepted: false,
|
||||
errorType: "method",
|
||||
message: "Check successful.",
|
||||
codes: { status: 0, intercept: 0 },
|
||||
data: null,
|
||||
};
|
||||
} catch (error) {
|
||||
|
||||
@ -113,12 +113,11 @@ export function createLogin(
|
||||
if (storeToken.serverError) return authServerError();
|
||||
|
||||
return {
|
||||
auth: {
|
||||
error: false,
|
||||
errorType: "method",
|
||||
message: "Login successful.",
|
||||
codes: { status: 0, intercept: 0 },
|
||||
},
|
||||
error: false,
|
||||
intercepted: false,
|
||||
errorType: "method",
|
||||
message: "Login successful.",
|
||||
codes: { status: 0, intercept: 0 },
|
||||
data: { accessToken, refreshToken },
|
||||
};
|
||||
} catch (error) {
|
||||
|
||||
@ -71,12 +71,11 @@ export function createLogout(
|
||||
if (deleteToken.serverError) return authServerError();
|
||||
|
||||
return {
|
||||
auth: {
|
||||
error: false,
|
||||
errorType: "method",
|
||||
message: "Logout successful.",
|
||||
codes: { status: 0, intercept: 0 },
|
||||
},
|
||||
error: false,
|
||||
intercepted: false,
|
||||
errorType: "method",
|
||||
message: "Logout successful.",
|
||||
codes: { status: 0, intercept: 0 },
|
||||
data: null,
|
||||
};
|
||||
} catch (error) {
|
||||
|
||||
@ -71,12 +71,11 @@ export function createRefresh(
|
||||
);
|
||||
|
||||
return {
|
||||
auth: {
|
||||
error: false,
|
||||
errorType: "method",
|
||||
message: "Refresh successful.",
|
||||
codes: { status: 0, intercept: 0 },
|
||||
},
|
||||
error: false,
|
||||
intercepted: false,
|
||||
errorType: "method",
|
||||
message: "Refresh successful.",
|
||||
codes: { status: 0, intercept: 0 },
|
||||
data: { accessToken },
|
||||
};
|
||||
} catch (error) {
|
||||
|
||||
@ -130,12 +130,11 @@ export function createRegister(
|
||||
if (storeUser.serverError) return authServerError();
|
||||
|
||||
return {
|
||||
auth: {
|
||||
error: false,
|
||||
errorType: "method",
|
||||
message: "Registration successful.",
|
||||
codes: { status: 0, intercept: 0 },
|
||||
},
|
||||
error: false,
|
||||
intercepted: false,
|
||||
errorType: "method",
|
||||
message: "Registration successful.",
|
||||
codes: { status: 0, intercept: 0 },
|
||||
data: { id: user.id, email: user.email, username: user.username },
|
||||
};
|
||||
} catch (error) {
|
||||
|
||||
@ -40,12 +40,11 @@ export function createValidate(
|
||||
}
|
||||
|
||||
return {
|
||||
auth: {
|
||||
error: false,
|
||||
errorType: "method",
|
||||
message: "Validation successful.",
|
||||
codes: { status: 0, intercept: 0 },
|
||||
},
|
||||
error: false,
|
||||
intercepted: false,
|
||||
errorType: "method",
|
||||
message: "Validation successful.",
|
||||
codes: { status: 0, intercept: 0 },
|
||||
data: { id: decodeAccessToken.payload.id },
|
||||
};
|
||||
} catch (error) {
|
||||
|
||||
@ -9,14 +9,13 @@ export function authError<
|
||||
interceptCode: number = 0
|
||||
): AuthResponse<Method> {
|
||||
return {
|
||||
auth: {
|
||||
error: true,
|
||||
errorType: "method",
|
||||
message: message,
|
||||
codes: {
|
||||
status: statusCode,
|
||||
intercept: interceptCode,
|
||||
},
|
||||
error: true,
|
||||
intercepted: interceptCode === 0 ? false : true,
|
||||
errorType: "method",
|
||||
message: message,
|
||||
codes: {
|
||||
status: statusCode,
|
||||
intercept: interceptCode,
|
||||
},
|
||||
data: null,
|
||||
} as AuthResponse<Method>;
|
||||
@ -24,12 +23,11 @@ export function authError<
|
||||
|
||||
export function authServerError(): AuthProtocol[keyof AuthProtocol]["responses"]["server_5"] {
|
||||
return {
|
||||
auth: {
|
||||
error: true,
|
||||
errorType: "server",
|
||||
message: "An error occurred on the server. Please try again later.",
|
||||
codes: { status: 5, intercept: 0 },
|
||||
},
|
||||
error: true,
|
||||
intercepted: false,
|
||||
errorType: "server",
|
||||
message: "An error occurred on the server. Please try again later.",
|
||||
codes: { status: 5, intercept: 0 },
|
||||
data: null,
|
||||
};
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user