Skip to content

Commit

Permalink
feat: Add user + auth (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
KirillDogadin-std authored Mar 22, 2023
1 parent 38c5a60 commit 125d8b1
Show file tree
Hide file tree
Showing 23 changed files with 1,597 additions and 83 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
push:
branches: [ main ]

env:
DATABASE_URL: file:./db.sqlite
AUTH_SIGNUP_ENABLED: 1
jobs:
build:

Expand All @@ -21,6 +24,8 @@ jobs:

- run: npm install

- run: npx prisma db push

- run: npm run typecheck

- run: npm run lint
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@ to automatically use the correct node version. The version is detected from the

If you do not have a code editor setup, we recommend that you use [Visual Studio Code](https://code.visualstudio.com/) to get started. It is very beginner friendly and you can move on to something else (such as Sublime, vim, emacs, ...) down the road if you want to.

Some environment variables are pre-configured for the development. You can copy them over to your `.env` file by running:

```sh
cp developer.env .env
```

### Environment variables

- `DATABASE_URL` (required): path to the database file.
- `JWT_SECRET` (required): server's jwt secret.
- `PORT` (optional, default: 3000): port on which the server will run.
- `AUTH_SIGNUP_ENABLED` (optional, default: `false`): if signing up mutation is allowed (i.e. user creation via endpoint is enabled)
- `JWT_EXPIRATION_PERIOD` (optional, default: `'7d'`): how soon the signed jwt token will expire.

### Project-Requirements

To understand bettwe that is planned, you can read and ask questions here:
Expand Down
11 changes: 11 additions & 0 deletions developer.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Prisma db
DATABASE_URL="file:./db.sqlite"

# Replacement JWT_SECRET
JWT_SECRET="developer"

# enable sign up for development
AUTH_SIGNUP_ENABLED="1"

# jwt token expiration period in seconds (Auth)
JWT_EXPIRATION_PERIOD_SECONDS=3600
52 changes: 51 additions & 1 deletion generated/nexus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ declare global {
}

export interface NexusGenInputs {
UserNamePass: { // input type
password: string; // String!
username: string; // String!
}
}

export interface NexusGenEnums {
Expand All @@ -43,6 +47,10 @@ export interface NexusGenScalars {
}

export interface NexusGenObjects {
AuthPayload: { // root type
token?: string | null; // String
user?: NexusGenRootTypes['User'] | null; // User
}
CoreUnit: { // root type
code?: string | null; // String
descriptionParagraph?: string | null; // String
Expand All @@ -53,7 +61,13 @@ export interface NexusGenObjects {
name?: string | null; // String
shortCode?: string | null; // String
}
Mutation: {};
Query: {};
User: { // root type
id?: string | null; // String
password?: string | null; // String
username?: string | null; // String
}
}

export interface NexusGenInterfaces {
Expand All @@ -67,6 +81,10 @@ export type NexusGenRootTypes = NexusGenObjects
export type NexusGenAllTypes = NexusGenRootTypes & NexusGenScalars

export interface NexusGenFieldTypes {
AuthPayload: { // field return type
token: string | null; // String
user: NexusGenRootTypes['User'] | null; // User
}
CoreUnit: { // field return type
code: string | null; // String
descriptionParagraph: string | null; // String
Expand All @@ -77,13 +95,27 @@ export interface NexusGenFieldTypes {
name: string | null; // String
shortCode: string | null; // String
}
Mutation: { // field return type
signIn: NexusGenRootTypes['AuthPayload'] | null; // AuthPayload
signUp: NexusGenRootTypes['AuthPayload'] | null; // AuthPayload
}
Query: { // field return type
coreUnit: NexusGenRootTypes['CoreUnit'] | null; // CoreUnit
coreUnits: Array<NexusGenRootTypes['CoreUnit'] | null> | null; // [CoreUnit]
me: NexusGenRootTypes['User'] | null; // User
}
User: { // field return type
id: string | null; // String
password: string | null; // String
username: string | null; // String
}
}

export interface NexusGenFieldTypeNames {
AuthPayload: { // field return type name
token: 'String'
user: 'User'
}
CoreUnit: { // field return type name
code: 'String'
descriptionParagraph: 'String'
Expand All @@ -94,13 +126,31 @@ export interface NexusGenFieldTypeNames {
name: 'String'
shortCode: 'String'
}
Mutation: { // field return type name
signIn: 'AuthPayload'
signUp: 'AuthPayload'
}
Query: { // field return type name
coreUnit: 'CoreUnit'
coreUnits: 'CoreUnit'
me: 'User'
}
User: { // field return type name
id: 'String'
password: 'String'
username: 'String'
}
}

export interface NexusGenArgTypes {
Mutation: {
signIn: { // args
user: NexusGenInputs['UserNamePass']; // UserNamePass!
}
signUp: { // args
user: NexusGenInputs['UserNamePass']; // UserNamePass!
}
}
Query: {
coreUnit: { // args
id?: string | null; // String
Expand All @@ -116,7 +166,7 @@ export interface NexusGenTypeInterfaces {

export type NexusGenObjectNames = keyof NexusGenObjects;

export type NexusGenInputNames = never;
export type NexusGenInputNames = keyof NexusGenInputs;

export type NexusGenEnumNames = never;

Expand Down
22 changes: 22 additions & 0 deletions generated/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
### Do not make changes to this file directly


type AuthPayload {
token: String
user: User
}

type CoreUnit {
code: String
descriptionParagraph: String
Expand All @@ -13,7 +18,24 @@ type CoreUnit {
shortCode: String
}

type Mutation {
signIn(user: UserNamePass!): AuthPayload
signUp(user: UserNamePass!): AuthPayload
}

type Query {
coreUnit(id: String): CoreUnit
coreUnits: [CoreUnit]
me: User
}

type User {
id: String
password: String
username: String
}

input UserNamePass {
password: String!
username: String!
}
Loading

0 comments on commit 125d8b1

Please sign in to comment.