-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
20 additions
and
6 deletions.
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
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,2 +1 @@ | ||
CLIENT_ID=afaac908-1db3-4b5c-a7ae-c040b9684403 | ||
CLIENT_SECRET=03e8c3e1-e483-47a6-a225-b05a22e4c523 |
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 @@ | ||
CLIENT_SECRET=03e8c3e1-e483-47a6-a225-b05a22e4c523 |
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,29 +1,34 @@ | ||
import * as functions from "firebase-functions"; | ||
import {auth, logger} from "firebase-functions"; | ||
import {ChatKitty} from "chatkitty-platform-sdk"; | ||
|
||
const chatkitty = new ChatKitty({ | ||
clientId: process.env.CLIENT_ID as string, | ||
clientSecret: process.env.CLIENT_SECRET as string, | ||
}); | ||
|
||
|
||
export const handleCreateUser = | ||
functions.auth.user().onCreate(async (user) => { | ||
auth.user().onCreate(async (user) => { | ||
await chatkitty.Users.checkUserExists(user.uid).catch(async () => { | ||
await chatkitty.Users.createUser({ | ||
name: user.uid, | ||
displayName: user.displayName || "anonymous", | ||
isGuest: true, | ||
}); | ||
}); | ||
|
||
logger.info(`Successfully created ChatKitty user: ${user.uid}`); | ||
}); | ||
|
||
export const handleDeleteUser = functions.auth.user().onDelete(async (user) => { | ||
export const handleDeleteUser = auth.user().onDelete(async (user) => { | ||
const result = await chatkitty.Users.listUsers(0, 0, undefined, user.uid); | ||
|
||
const users = result.data._embedded?.users; | ||
|
||
if (users && users.length > 0) { | ||
await chatkitty.Users.deleteUser(users[0].id); | ||
|
||
logger.info(`Successfully deleted ChatKitty user: ${user.uid}`); | ||
} else { | ||
logger.info(`ChatKitty user not found: ${user.uid}`); | ||
} | ||
}); |