Skip to content

Commit

Permalink
Add auth interceptors for admin client
Browse files Browse the repository at this point in the history
  • Loading branch information
hackerwins committed Aug 2, 2022
1 parent 1281e4e commit addb92a
Show file tree
Hide file tree
Showing 19 changed files with 1,744 additions and 378 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@
"grpc",
"bg",
"str",
"signup"
"signup",
"unary",
"invoker"
],
"skipIfMatch": [
"TODO\\(.+\\):",
Expand Down
30 changes: 22 additions & 8 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@
import React from 'react';
import { BrowserRouter as Router, Routes, Route, Navigate } from 'react-router-dom';
import { Projects, CreateProject, ProjectAPIKeys, Project, Documents, ProjectSettings, Login, Signup } from 'routes';
import {
Login,
Signup,
PrivateRoute,
Projects,
CreateProject,
ProjectAPIKeys,
Project,
Documents,
ProjectSettings,
} from 'routes';

function App() {
// TODO(hackerwins): If the user is already logged in, redirect to the
// projects page.
return (
<Router>
<Routes>
<Route path="/login" element={<Login />} />
<Route path="/signup" element={<Signup />} />
<Route path="/projects" element={<Projects />} />
<Route path="/projects/new" element={<CreateProject />} />
<Route path="/projects/:projectName" element={<Project />} />
<Route path="/projects/:projectName/apikeys" element={<ProjectAPIKeys />} />
<Route path="/projects/:projectName/documents/*" element={<Documents />} />
<Route path="/projects/:projectName/settings" element={<ProjectSettings />} />
<Route path="/" element={<Navigate to="/projects" />} />
<Route element={<PrivateRoute />}>
<Route path="/" element={<Navigate to="/projects" />} />
<Route path="/projects" element={<Projects />} />
<Route path="/projects/new" element={<CreateProject />} />
<Route path="/projects/:projectName" element={<Project />} />
<Route path="/projects/:projectName/apikeys" element={<ProjectAPIKeys />} />
<Route path="/projects/:projectName/documents/*" element={<Documents />} />
<Route path="/projects/:projectName/settings" element={<ProjectSettings />} />
</Route>
</Routes>
</Router>
);
Expand Down
21 changes: 21 additions & 0 deletions src/api/admin.proto
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import "resources.proto";

// Admin is a service that provides a API for Admin.
service Admin {
rpc SignUp(SignUpRequest) returns (SignUpResponse) {}
rpc LogIn(LogInRequest) returns (LogInResponse) {}

rpc CreateProject(CreateProjectRequest) returns (CreateProjectResponse) {}
rpc ListProjects(ListProjectsRequest) returns (ListProjectsResponse) {}
rpc GetProject(GetProjectRequest) returns (GetProjectResponse) {}
Expand All @@ -34,6 +37,24 @@ service Admin {
rpc ListChanges (ListChangesRequest) returns (ListChangesResponse) {}
}

message SignUpRequest {
string username = 1;
string password = 2;
}

message SignUpResponse {
User user = 1;
}

message LogInRequest {
string username = 1;
string password = 2;
}

message LogInResponse {
string token = 1;
}

message CreateProjectRequest {
string name = 1;
}
Expand Down
24 changes: 24 additions & 0 deletions src/api/admin_grpc_web_pb.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@ export class AdminClient {
credentials?: null | { [index: string]: string; },
options?: null | { [index: string]: any; });

signUp(
request: admin_pb.SignUpRequest,
metadata: grpcWeb.Metadata | undefined,
callback: (err: grpcWeb.RpcError,
response: admin_pb.SignUpResponse) => void
): grpcWeb.ClientReadableStream<admin_pb.SignUpResponse>;

logIn(
request: admin_pb.LogInRequest,
metadata: grpcWeb.Metadata | undefined,
callback: (err: grpcWeb.RpcError,
response: admin_pb.LogInResponse) => void
): grpcWeb.ClientReadableStream<admin_pb.LogInResponse>;

createProject(
request: admin_pb.CreateProjectRequest,
metadata: grpcWeb.Metadata | undefined,
Expand Down Expand Up @@ -78,6 +92,16 @@ export class AdminPromiseClient {
credentials?: null | { [index: string]: string; },
options?: null | { [index: string]: any; });

signUp(
request: admin_pb.SignUpRequest,
metadata?: grpcWeb.Metadata
): Promise<admin_pb.SignUpResponse>;

logIn(
request: admin_pb.LogInRequest,
metadata?: grpcWeb.Metadata
): Promise<admin_pb.LogInResponse>;

createProject(
request: admin_pb.CreateProjectRequest,
metadata?: grpcWeb.Metadata
Expand Down
122 changes: 122 additions & 0 deletions src/api/admin_grpc_web_pb.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,128 @@ proto.api.AdminPromiseClient =
};


/**
* @const
* @type {!grpc.web.MethodDescriptor<
* !proto.api.SignUpRequest,
* !proto.api.SignUpResponse>}
*/
const methodDescriptor_Admin_SignUp = new grpc.web.MethodDescriptor(
'/api.Admin/SignUp',
grpc.web.MethodType.UNARY,
proto.api.SignUpRequest,
proto.api.SignUpResponse,
/**
* @param {!proto.api.SignUpRequest} request
* @return {!Uint8Array}
*/
function(request) {
return request.serializeBinary();
},
proto.api.SignUpResponse.deserializeBinary
);


/**
* @param {!proto.api.SignUpRequest} request The
* request proto
* @param {?Object<string, string>} metadata User defined
* call metadata
* @param {function(?grpc.web.RpcError, ?proto.api.SignUpResponse)}
* callback The callback function(error, response)
* @return {!grpc.web.ClientReadableStream<!proto.api.SignUpResponse>|undefined}
* The XHR Node Readable Stream
*/
proto.api.AdminClient.prototype.signUp =
function(request, metadata, callback) {
return this.client_.rpcCall(this.hostname_ +
'/api.Admin/SignUp',
request,
metadata || {},
methodDescriptor_Admin_SignUp,
callback);
};


/**
* @param {!proto.api.SignUpRequest} request The
* request proto
* @param {?Object<string, string>=} metadata User defined
* call metadata
* @return {!Promise<!proto.api.SignUpResponse>}
* Promise that resolves to the response
*/
proto.api.AdminPromiseClient.prototype.signUp =
function(request, metadata) {
return this.client_.unaryCall(this.hostname_ +
'/api.Admin/SignUp',
request,
metadata || {},
methodDescriptor_Admin_SignUp);
};


/**
* @const
* @type {!grpc.web.MethodDescriptor<
* !proto.api.LogInRequest,
* !proto.api.LogInResponse>}
*/
const methodDescriptor_Admin_LogIn = new grpc.web.MethodDescriptor(
'/api.Admin/LogIn',
grpc.web.MethodType.UNARY,
proto.api.LogInRequest,
proto.api.LogInResponse,
/**
* @param {!proto.api.LogInRequest} request
* @return {!Uint8Array}
*/
function(request) {
return request.serializeBinary();
},
proto.api.LogInResponse.deserializeBinary
);


/**
* @param {!proto.api.LogInRequest} request The
* request proto
* @param {?Object<string, string>} metadata User defined
* call metadata
* @param {function(?grpc.web.RpcError, ?proto.api.LogInResponse)}
* callback The callback function(error, response)
* @return {!grpc.web.ClientReadableStream<!proto.api.LogInResponse>|undefined}
* The XHR Node Readable Stream
*/
proto.api.AdminClient.prototype.logIn =
function(request, metadata, callback) {
return this.client_.rpcCall(this.hostname_ +
'/api.Admin/LogIn',
request,
metadata || {},
methodDescriptor_Admin_LogIn,
callback);
};


/**
* @param {!proto.api.LogInRequest} request The
* request proto
* @param {?Object<string, string>=} metadata User defined
* call metadata
* @return {!Promise<!proto.api.LogInResponse>}
* Promise that resolves to the response
*/
proto.api.AdminPromiseClient.prototype.logIn =
function(request, metadata) {
return this.client_.unaryCall(this.hostname_ +
'/api.Admin/LogIn',
request,
metadata || {},
methodDescriptor_Admin_LogIn);
};


/**
* @const
* @type {!grpc.web.MethodDescriptor<
Expand Down
82 changes: 82 additions & 0 deletions src/api/admin_pb.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,88 @@ import * as jspb from 'google-protobuf'
import * as resources_pb from './resources_pb';


export class SignUpRequest extends jspb.Message {
getUsername(): string;
setUsername(value: string): SignUpRequest;

getPassword(): string;
setPassword(value: string): SignUpRequest;

serializeBinary(): Uint8Array;
toObject(includeInstance?: boolean): SignUpRequest.AsObject;
static toObject(includeInstance: boolean, msg: SignUpRequest): SignUpRequest.AsObject;
static serializeBinaryToWriter(message: SignUpRequest, writer: jspb.BinaryWriter): void;
static deserializeBinary(bytes: Uint8Array): SignUpRequest;
static deserializeBinaryFromReader(message: SignUpRequest, reader: jspb.BinaryReader): SignUpRequest;
}

export namespace SignUpRequest {
export type AsObject = {
username: string,
password: string,
}
}

export class SignUpResponse extends jspb.Message {
getUser(): resources_pb.User | undefined;
setUser(value?: resources_pb.User): SignUpResponse;
hasUser(): boolean;
clearUser(): SignUpResponse;

serializeBinary(): Uint8Array;
toObject(includeInstance?: boolean): SignUpResponse.AsObject;
static toObject(includeInstance: boolean, msg: SignUpResponse): SignUpResponse.AsObject;
static serializeBinaryToWriter(message: SignUpResponse, writer: jspb.BinaryWriter): void;
static deserializeBinary(bytes: Uint8Array): SignUpResponse;
static deserializeBinaryFromReader(message: SignUpResponse, reader: jspb.BinaryReader): SignUpResponse;
}

export namespace SignUpResponse {
export type AsObject = {
user?: resources_pb.User.AsObject,
}
}

export class LogInRequest extends jspb.Message {
getUsername(): string;
setUsername(value: string): LogInRequest;

getPassword(): string;
setPassword(value: string): LogInRequest;

serializeBinary(): Uint8Array;
toObject(includeInstance?: boolean): LogInRequest.AsObject;
static toObject(includeInstance: boolean, msg: LogInRequest): LogInRequest.AsObject;
static serializeBinaryToWriter(message: LogInRequest, writer: jspb.BinaryWriter): void;
static deserializeBinary(bytes: Uint8Array): LogInRequest;
static deserializeBinaryFromReader(message: LogInRequest, reader: jspb.BinaryReader): LogInRequest;
}

export namespace LogInRequest {
export type AsObject = {
username: string,
password: string,
}
}

export class LogInResponse extends jspb.Message {
getToken(): string;
setToken(value: string): LogInResponse;

serializeBinary(): Uint8Array;
toObject(includeInstance?: boolean): LogInResponse.AsObject;
static toObject(includeInstance: boolean, msg: LogInResponse): LogInResponse.AsObject;
static serializeBinaryToWriter(message: LogInResponse, writer: jspb.BinaryWriter): void;
static deserializeBinary(bytes: Uint8Array): LogInResponse;
static deserializeBinaryFromReader(message: LogInResponse, reader: jspb.BinaryReader): LogInResponse;
}

export namespace LogInResponse {
export type AsObject = {
token: string,
}
}

export class CreateProjectRequest extends jspb.Message {
getName(): string;
setName(value: string): CreateProjectRequest;
Expand Down
Loading

0 comments on commit addb92a

Please sign in to comment.