-
Notifications
You must be signed in to change notification settings - Fork 1
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
User Auth with SIWE + Permissioned Area i.e. Dashboard #149
Merged
Merged
Changes from 15 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
8c3adf9
scaffold user module + documentation cleanup
wtfsayo a1c120c
save: create `shell` enterprise and tenant for the new user
wtfsayo 54888a0
save: tear down, direct tenant key creation
wtfsayo 0d3dd56
save
wtfsayo 6dab2aa
wip:save
wtfsayo 428a74c
save:wip
wtfsayo d4dc11d
feat: dashboard layout
wtfsayo 40055b9
imporvement to dashboard apis
wtfsayo d403318
updates: styling
wtfsayo 5323c6b
save: login page
wtfsayo e6a6814
save: login styling
wtfsayo 57e8b7d
wip: switching to client components only
wtfsayo 3ec14d2
save:temp
wtfsayo 9af93ed
save: big win; siwe
wtfsayo 9cf41a9
biglift: siwe and login/dashboard
wtfsayo cfbe769
pull off bun files
wtfsayo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This probably shouldn't be checked in. Correct me if I'm wrong. |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { AppsController } from './apps.controller'; | ||
|
||
describe('AppsController', () => { | ||
let controller: AppsController; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
controllers: [AppsController], | ||
}).compile(); | ||
|
||
controller = module.get<AppsController>(AppsController); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(controller).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Controller, Get, Param, Post } from '@nestjs/common'; | ||
import { AppsService } from './apps.service'; | ||
|
||
@Controller('apps') | ||
export class AppsController { | ||
constructor(private readonly appsService: AppsService) {} | ||
|
||
@Get(':userAddress') | ||
async getUserApps(@Param('userAddress') userAddress: string) { | ||
// @note: This action fetches apps by tenant; | ||
return this.appsService.getAppsByUser(userAddress); | ||
} | ||
|
||
@Post(':userAddress') | ||
async createApp(@Param('userAddress') userAddress: string) { | ||
// @note: This action creates app for tenant by enterpriseId; | ||
return this.appsService.createApp(userAddress); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { AppsController } from './apps.controller'; | ||
import { AppsService } from './apps.service'; | ||
import { UserService } from '../user/user.service'; | ||
import { TenantService } from '../tenant/tenant.service'; | ||
|
||
@Module({ | ||
controllers: [AppsController], | ||
providers: [AppsService, UserService, TenantService], | ||
}) | ||
export class AppsModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { AppsService } from './apps.service'; | ||
|
||
describe('AppsService', () => { | ||
let service: AppsService; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [AppsService], | ||
}).compile(); | ||
|
||
service = module.get<AppsService>(AppsService); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(service).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { Injectable, Inject, HttpException, HttpStatus } from '@nestjs/common'; | ||
import { CustomPrismaService } from 'nestjs-prisma'; | ||
import { PrismaClient } from '@/.generated/client'; | ||
import { UserService } from '../user/user.service'; | ||
@Injectable() | ||
export class AppsService { | ||
constructor( | ||
@Inject('Postgres') | ||
private prisma: CustomPrismaService<PrismaClient>, // <-- Inject the PrismaClient | ||
private userService: UserService, | ||
) {} | ||
|
||
async getTenantsByUser(userAddress: string) { | ||
const user = await this.userService.getOrCreate(userAddress); | ||
|
||
const enterprises = user.orgs.map((org) => org.enterpriseId); | ||
|
||
const tenants = await this.prisma.client.tenant.findMany({ | ||
where: { | ||
enterpriseId: { | ||
in: enterprises, | ||
}, | ||
}, | ||
}); | ||
|
||
if (!tenants || tenants.length === 0) { | ||
throw new HttpException('No tenants found', HttpStatus.NOT_FOUND); | ||
} | ||
return tenants; | ||
} | ||
|
||
async getAppsByUser(userAddress: string) { | ||
const tenants = await this.getTenantsByUser(userAddress); | ||
const apps = await this.prisma.client.app.findMany({ | ||
where: { | ||
tenantId: { | ||
in: tenants.map((tenant) => tenant.id), | ||
}, | ||
}, | ||
include: { | ||
appRules: true, | ||
}, | ||
}); | ||
|
||
if (!apps || apps?.length === 0) { | ||
throw new HttpException('No apps found', HttpStatus.NOT_FOUND); | ||
} | ||
return apps; | ||
} | ||
|
||
async createApp(userAddress: string) { | ||
const tenants = await this.getTenantsByUser(userAddress); | ||
|
||
if (!tenants) return; | ||
const newApp = await this.prisma.client.app.create({ | ||
data: { | ||
tenantId: tenants[0].id, | ||
}, | ||
}); | ||
|
||
if (!newApp) { | ||
return new HttpException( | ||
`Could not create app for this tenant`, | ||
HttpStatus.INTERNAL_SERVER_ERROR, | ||
); | ||
} | ||
|
||
return newApp; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { OrgController } from './org.controller'; | ||
|
||
describe('OrgController', () => { | ||
let controller: OrgController; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
controllers: [OrgController], | ||
}).compile(); | ||
|
||
controller = module.get<OrgController>(OrgController); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(controller).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { Controller } from '@nestjs/common'; | ||
|
||
@Controller('org') | ||
export class OrgController {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { OrgController } from './org.controller'; | ||
import { OrgService } from './org.service'; | ||
|
||
@Module({ | ||
controllers: [OrgController], | ||
providers: [OrgService] | ||
}) | ||
export class OrgModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { OrgService } from './org.service'; | ||
|
||
describe('OrgService', () => { | ||
let service: OrgService; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [OrgService], | ||
}).compile(); | ||
|
||
service = module.get<OrgService>(OrgService); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(service).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Injectable, Inject } from '@nestjs/common'; | ||
import { CustomPrismaService } from 'nestjs-prisma'; | ||
import { PrismaClient } from '@/.generated/client'; | ||
|
||
@Injectable() | ||
export class OrgService { | ||
constructor( | ||
@Inject('Postgres') | ||
private prisma: CustomPrismaService<PrismaClient>, // <-- Inject the PrismaClient | ||
) {} | ||
|
||
async getOrgsByUser(userId: string) { | ||
const org = this.prisma.client.org.findMany({ | ||
where: { | ||
users: { | ||
every: { | ||
id: userId, | ||
}, | ||
}, | ||
}, | ||
}); | ||
return org; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { SiweController } from './siwe.controller'; | ||
import { SiweService } from './siwe.service'; | ||
import { UserService } from '../user/user.service'; | ||
import { TenantService } from '../tenant/tenant.service'; | ||
|
||
@Module({ | ||
controllers: [SiweController], | ||
providers: [SiweService], | ||
providers: [SiweService, UserService, TenantService], | ||
exports: [SiweService], | ||
}) | ||
export class SiweModule {} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will require a reset of the db right? Fine here, but we should really start getting into better habits re: migration.