mirror of
https://github.com/sasjs/server.git
synced 2026-01-08 15:00:05 +00:00
test(auth): added for authorize + token
This commit is contained in:
22
src/controllers/createClient.ts
Normal file
22
src/controllers/createClient.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import Client from '../model/Client'
|
||||
|
||||
export const createClient = async (data: any) => {
|
||||
const { clientid, clientsecret } = data
|
||||
|
||||
// Checking if client is already in the database
|
||||
const clientExist = await Client.findOne({ clientid })
|
||||
if (clientExist) throw new Error('Client ID already exists.')
|
||||
|
||||
// Create a new client
|
||||
const client = new Client({
|
||||
clientid,
|
||||
clientsecret
|
||||
})
|
||||
|
||||
const savedClient = await client.save()
|
||||
|
||||
return {
|
||||
clientid: savedClient.clientid,
|
||||
clientsecret: savedClient.clientsecret
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user