@@ -4,6 +4,7 @@ import { FastifyInstance, FastifyPluginCallback, FastifyRequest } from 'fastify'
44import type { InjectedAccountWithMeta } from '@polkadot/extension-inject/types'
55import { getSession , getUserByProvider , isValidSignature } from '../helper'
66import { ExtensionAccount } from '#client/components/auth/helper'
7+ import config from '#server/config'
78
89export const plugin : FastifyPluginCallback = async (
910 fastify : FastifyInstance
@@ -12,11 +13,11 @@ export const plugin: FastifyPluginCallback = async (
1213 '/users' ,
1314 async (
1415 req : FastifyRequest < {
15- Body : { selectedAccount : InjectedAccountWithMeta ; signature : string }
16+ Body : { selectedAccount : ExtensionAccount ; signature : string }
1617 } > ,
1718 reply
1819 ) => {
19- const body : InjectedAccountWithMeta = req . body . selectedAccount
20+ const body : ExtensionAccount = req . body . selectedAccount
2021 const isSignatureValid = isValidSignature (
2122 body . address ,
2223 req . body . signature
@@ -35,11 +36,15 @@ export const plugin: FastifyPluginCallback = async (
3536 '/login' ,
3637 async (
3738 req : FastifyRequest < {
38- Body : { selectedAccount : InjectedAccountWithMeta ; signature : string }
39+ Body : { selectedAccount : ExtensionAccount ; signature : string }
3940 } > ,
4041 reply
4142 ) => {
42- const body : InjectedAccountWithMeta = req . body . selectedAccount
43+ const body : ExtensionAccount = req . body . selectedAccount
44+ const source = body . source ?. replace ( / / g, '' ) . toLowerCase ( )
45+ if ( ! config . allowedWallets . includes ( source ) ) {
46+ return reply . throw . conflict ( 'Unsupported extension' )
47+ }
4348 const isSignatureValid = isValidSignature (
4449 body . address ,
4550 req . body . signature
@@ -69,17 +74,8 @@ export const plugin: FastifyPluginCallback = async (
6974 ) => {
7075 const body : ExtensionAccount = req . body . selectedAccount
7176 const source = body . source ?. replace ( / / g, '' ) . toLowerCase ( )
72- // @todo move to app config?
73- const allowedPolkadotAuthProviders = [
74- 'polkadot-js' ,
75- 'talisman' ,
76- 'subwallet-js' ,
77- 'subwallet' ,
78- 'novawallet' ,
79- 'walletconnect' ,
80- ]
8177
82- if ( ! allowedPolkadotAuthProviders . includes ( source ) ) {
78+ if ( ! config . allowedWallets . includes ( source ) ) {
8379 return reply . throw . conflict ( 'Unsupported extension' )
8480 }
8581
0 commit comments