Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add user + auth #16

Merged
merged 77 commits into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from 49 commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
5a67958
broken boilerplate added
KirillDogadin-std Mar 9, 2023
7e9f9bf
fix
KirillDogadin-std Mar 10, 2023
205d09b
refactor: env variable extraction
KirillDogadin-std Mar 13, 2023
77f01fd
Polishing
KirillDogadin-std Mar 13, 2023
98c297f
fix typecheck
KirillDogadin-std Mar 13, 2023
4803bcc
fix me resolver
KirillDogadin-std Mar 13, 2023
091521d
remove subscription
KirillDogadin-std Mar 13, 2023
9ece599
merge modules
KirillDogadin-std Mar 13, 2023
b47e259
as above
KirillDogadin-std Mar 13, 2023
22023f2
move getUser
KirillDogadin-std Mar 13, 2023
f04788b
error handling
KirillDogadin-std Mar 13, 2023
680fbdd
use newer lib
KirillDogadin-std Mar 13, 2023
a42a02c
remove old lib
KirillDogadin-std Mar 13, 2023
58ba012
as above
KirillDogadin-std Mar 13, 2023
6ac1fcf
adjust the schema
KirillDogadin-std Mar 14, 2023
82f0c0e
adjust the context creation
KirillDogadin-std Mar 14, 2023
9a89f6a
adjust used schema
KirillDogadin-std Mar 14, 2023
f1c299f
signup enable flag
KirillDogadin-std Mar 14, 2023
68fe314
lint
KirillDogadin-std Mar 14, 2023
8a5690b
handle expiration
KirillDogadin-std Mar 14, 2023
fcb61b4
adjust expiration period
KirillDogadin-std Mar 14, 2023
5ab1090
configurable expiration period
KirillDogadin-std Mar 14, 2023
6aca5cd
lint
KirillDogadin-std Mar 14, 2023
a94b0cb
lint
KirillDogadin-std Mar 14, 2023
6acf830
move logic from server to index
KirillDogadin-std Mar 14, 2023
19b58d1
remove server file
KirillDogadin-std Mar 14, 2023
c621658
simplify index
KirillDogadin-std Mar 14, 2023
62e965f
rm disposable
KirillDogadin-std Mar 14, 2023
a0c4e3a
rm useless packages
KirillDogadin-std Mar 14, 2023
2977b10
only check auth at a single place
KirillDogadin-std Mar 14, 2023
f5e9601
do the operations in models file
KirillDogadin-std Mar 14, 2023
9f5bc1f
lint
KirillDogadin-std Mar 14, 2023
02f65ac
more lint
KirillDogadin-std Mar 14, 2023
1435269
rename
KirillDogadin-std Mar 14, 2023
146d6ce
typecheck
KirillDogadin-std Mar 14, 2023
6a8e032
typecheck
KirillDogadin-std Mar 14, 2023
114b2eb
change me endpoing
KirillDogadin-std Mar 14, 2023
70b8e48
refactor: prisma extend
KirillDogadin-std Mar 15, 2023
3eefbf9
move auth logic
KirillDogadin-std Mar 15, 2023
134b4ea
Add env vars
KirillDogadin-std Mar 16, 2023
514f2aa
auth logic refactor
KirillDogadin-std Mar 16, 2023
229af23
rm shield dep
KirillDogadin-std Mar 16, 2023
0090f6b
add tests
KirillDogadin-std Mar 17, 2023
0b7e870
lint;
KirillDogadin-std Mar 17, 2023
ef6c173
fix secret set
KirillDogadin-std Mar 17, 2023
89477f4
lint
KirillDogadin-std Mar 17, 2023
363b9f5
ci
KirillDogadin-std Mar 17, 2023
1833e2b
as above
KirillDogadin-std Mar 17, 2023
cd61f1f
as above
KirillDogadin-std Mar 17, 2023
9b16328
remove installs
KirillDogadin-std Mar 20, 2023
e009c4c
adjust the test to by sync test
KirillDogadin-std Mar 20, 2023
6e866f5
rm git-port
KirillDogadin-std Mar 20, 2023
240eda6
replace localhost with 0000
KirillDogadin-std Mar 20, 2023
d9e2579
return object instead of factory collection
KirillDogadin-std Mar 20, 2023
4a833ae
fix test
KirillDogadin-std Mar 20, 2023
15f4417
add test
KirillDogadin-std Mar 20, 2023
eb05d93
add test
KirillDogadin-std Mar 20, 2023
94985d8
nit
KirillDogadin-std Mar 20, 2023
8de75ab
refactor: accept clean token instead of header
KirillDogadin-std Mar 20, 2023
1b81069
refactor
KirillDogadin-std Mar 20, 2023
636a3cc
build queries
KirillDogadin-std Mar 20, 2023
0654113
use ts safe gql client
KirillDogadin-std Mar 20, 2023
58f21a0
programmatic invocation of type gen
KirillDogadin-std Mar 20, 2023
936b16c
comments
KirillDogadin-std Mar 20, 2023
7cb1f06
refactor
KirillDogadin-std Mar 20, 2023
e59bb18
rm dep
KirillDogadin-std Mar 20, 2023
6aa6420
lint
KirillDogadin-std Mar 20, 2023
5d396ec
rm dep
KirillDogadin-std Mar 21, 2023
8469cf7
Revert "lint"
KirillDogadin-std Mar 21, 2023
2f8d99d
Revert "rm dep"
KirillDogadin-std Mar 21, 2023
3e68e68
Revert "refactor"
KirillDogadin-std Mar 21, 2023
4d930ea
Revert "comments"
KirillDogadin-std Mar 21, 2023
b18f8ec
Revert "programmatic invocation of type gen"
KirillDogadin-std Mar 21, 2023
7cb3174
Revert "use ts safe gql client"
KirillDogadin-std Mar 21, 2023
420142f
recreate context before and after each
KirillDogadin-std Mar 21, 2023
8e68404
reduce hardcoded mutation count
KirillDogadin-std Mar 21, 2023
0c02054
lint
KirillDogadin-std Mar 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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