Skip to content

Commit

Permalink
Prep repo for development && remove unused routes
Browse files Browse the repository at this point in the history
  • Loading branch information
ccali11 committed Mar 20, 2023
1 parent c4fda2b commit ecd01b8
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 86 deletions.
7 changes: 7 additions & 0 deletions apps/web/src/composables/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ import { ProviderString } from '@casimir/types'
const { usersBaseURL } = useEnvironment()

export default function useAuth() {
/**
* Gets a message from the server to sign
*
* @param {ProviderString} provider - The provider the user is using to sign in
* @param {string} address - The user's address
* @returns {Promise<Response>} - The response from the message request
*/
async function getMessage(provider: ProviderString, address: string) {
const requestOptions = {
method: 'GET',
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/composables/ethers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export default function useEthers() {
try {
const messageJson = await getMessage(provider, address)
const { message } = await messageJson.json()
// Temporarily return here to make sure we're adding to db correctly.
const signer = web3Provider.getSigner()
const signature = await signer.signMessage(message)
const response = await login({
Expand Down
2 changes: 2 additions & 0 deletions apps/web/src/composables/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,11 @@ export default function useWallet() {
loadingUserWallets.value = true
const connectedAddress = await getConnectedAddressFromProvider(provider, currency)
const connectedCurrency = await detectCurrencyInProvider(provider) as Currency
// STEP 0 & STEP 1
const response = await loginWithWallet(provider, connectedAddress, connectedCurrency)
if (!response?.error) {
// TODO: Handle case where user is not logged in / errors
// STEP 2
await getUserAccount() // This is querying the API for the user's account
setSelectedProvider(provider)
setSelectedAddress(connectedAddress)
Expand Down
2 changes: 0 additions & 2 deletions services/users/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import cors from 'cors'
import supertokens from 'supertokens-node'
import { middleware, errorHandler } from 'supertokens-node/framework/express'
import { SuperTokensBackendConfig } from './sessions.config'
import login from './routes/login'
import auth from './routes/auth'
import user from './routes/user'
import health from './routes/health'
Expand All @@ -30,7 +29,6 @@ app.use(
app.use(middleware())

app.use('/auth', auth)
app.use('/login', login)
app.use('/user', user)
app.use('/health', health)
app.use('/seed', seed)
Expand Down
9 changes: 7 additions & 2 deletions services/users/src/routes/auth.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import express from 'express'
import useUsers from '../providers/users'
import { userCollection } from '../collections/users'
import useDB from '../providers/db'
import Session from 'supertokens-node/recipe/session'
import useEthers from '../providers/ethers'
import { Account } from '@casimir/types'
import { LoginCredentials } from '@casimir/types'

const { verifyMessage } = useEthers()
const { getMessage, updateMessage } = useUsers()
const { getUser } = useDB()
const router = express.Router()


Expand All @@ -28,8 +29,11 @@ router.get('/message/:provider/:address', (req: express.Request, res: express.Re
router.use('/login', async (req: express.Request, res: express.Response) => {
const { body } = req
const { provider, address, currency, message, signedMessage } = body as LoginCredentials
const user = userCollection.find(user => user.address === address.toLowerCase())
// TODO: 3/20 Replace with checking if user exists in DB
const user = await getUser(address)
console.log('user :>> ', user)
if (user && !user?.accounts) { // signup
console.log('SIGNING UP!')
const accounts: Array<Account> = [
{
address: address,
Expand All @@ -50,6 +54,7 @@ router.use('/login', async (req: express.Request, res: express.Response) => {
error: false,
})
} else { // login
console.log('LOGGING IN!')
const response = verifyMessage({ address, currency, message, signedMessage, provider })
updateMessage(provider, address) // send back token if successful

Expand Down
27 changes: 0 additions & 27 deletions services/users/src/routes/login.ts

This file was deleted.

55 changes: 0 additions & 55 deletions services/users/src/routes/signup.ts

This file was deleted.

0 comments on commit ecd01b8

Please sign in to comment.