mirror of
https://iceshrimp.dev/iceshrimp/iceshrimp
synced 2024-11-24 23:26:07 +09:00
Refactor: Extract isNativeToken method
This commit is contained in:
parent
804808feb1
commit
a130246717
@ -2,6 +2,7 @@ import * as express from 'express';
|
||||
import App from './models/app';
|
||||
import User from './models/user';
|
||||
import Userkey from './models/userkey';
|
||||
import isNativeToken from './common/is-native-token';
|
||||
|
||||
export interface IAuthContext {
|
||||
/**
|
||||
@ -27,7 +28,7 @@ export default (req: express.Request) => new Promise<IAuthContext>(async (resolv
|
||||
return resolve({ app: null, user: null, isSecure: false });
|
||||
}
|
||||
|
||||
if (token[0] == '!') {
|
||||
if (isNativeToken(token)) {
|
||||
const user = await User
|
||||
.findOne({ token: token });
|
||||
|
||||
|
1
src/api/common/is-native-token.ts
Normal file
1
src/api/common/is-native-token.ts
Normal file
@ -0,0 +1 @@
|
||||
export default (token: string) => token[0] == '!';
|
@ -3,6 +3,7 @@ import * as websocket from 'websocket';
|
||||
import * as redis from 'redis';
|
||||
import User from './models/user';
|
||||
import Userkey from './models/userkey';
|
||||
import isNativeToken from './common/is-native-token';
|
||||
|
||||
import homeStream from './stream/home';
|
||||
import messagingStream from './stream/messaging';
|
||||
@ -50,7 +51,7 @@ module.exports = (server: http.Server) => {
|
||||
|
||||
function authenticate(connection: websocket.connection, token: string): Promise<any> {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
if (token[0] == '!') {
|
||||
if (isNativeToken(token)) {
|
||||
// Fetch user
|
||||
// SELECT _id
|
||||
const user = await User
|
||||
|
Loading…
Reference in New Issue
Block a user