本文整理汇总了TypeScript中jwt-decode.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了default函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: async
export default async (ctx: Context, next: Function) => {
const idToken = ctx.get('X-Id-Token');
const entityId = ctx.get('X-Entity-Id');
const entityType = ctx.get('X-Entity-Type');
if (!idToken || !entityId || !entityType) {
return reject(ctx);
}
try {
const token: any = decodeJWT(idToken);
const issuer = token.iss;
const identityId = token.unique_name;
if (!isKnownIssuer(issuer)) {
return reject(ctx);
}
let path = config.permissionsEndpoint.coursePath;
let data: any = { courseId: entityId };
if (entityType === constants.entityTypes.learningPath) {
path = config.permissionsEndpoint.learningPathPath;
data = { learningpathId: entityId };
}
let response;
if (issuer === 'localhost') {
response = { body: { data: constants.accessTypes.academy } };
} else {
response = await httpRequestSender.post(`https://${issuer}${path}`, data, {
Authorization: `Bearer ${idToken}`
});
if (!response || !response.body || response.statusCode !== 200) {
return reject(ctx);
}
}
ctx.entityId = entityId;
ctx.entityType = entityType;
ctx.identityId = identityId;
ctx.identityAccessLevel = response.body.data;
} catch (e) {
return reject(ctx);
}
await next();
};
示例2: switch
export const auth: Reducer<AuthState> = (
state = initialState,
action: FromActions.LoginActions | FromActions.LogoutAction | FromActions.RegisterActions,
) => {
let newToken = null;
switch (action.type) {
case FromActions.REGISTER_REQUEST:
case FromActions.LOGIN_REQUEST:
return {
...state,
errorMessage: null,
isAuthenticated: false,
isFetching: true,
};
case FromActions.REGISTER_SUCCESS:
newToken = jwtDecode<TokenDetails>(action.payload);
return {
...state,
email: newToken.email,
organizationId: newToken.organization_id,
errorMessage: null,
isFetching: false,
};
case FromActions.LOGIN_SUCCESS:
newToken = jwtDecode<TokenDetails>(action.payload);
return {
avatar: undefined,
email: newToken.email,
errorMessage: null,
isAuthenticated: true,
isFetching: false,
organizationId: newToken.organization_id,
role: newToken.role,
token: action.payload,
};
case FromActions.REGISTER_FAILURE:
case FromActions.LOGIN_FAILURE:
return {
avatar: undefined,
email: null,
errorMessage: action.payload,
isAuthenticated: false,
isFetching: false,
organizationId: null,
role: null,
token: null,
};
case FromActions.LOGOUT:
return {
avatar: undefined,
email: null,
errorMessage: null,
isAuthenticated: false,
isFetching: false,
organizationId: null,
role: null,
token: null,
};
default:
return state;
}
};
示例3: constructor
constructor(public router: Router) {
var jwt = localStorage.getItem('jwt');
if (jwt) {
var decodedJwt = jwtDecode(jwt);
this.isAdmin = decodedJwt._doc.admin;
}
}
示例4: isAuthenticated
public isAuthenticated(): boolean {
// get the token
const token = this.getToken();
if (token === null) { return false; }
const dToken = decode(token);
return (dToken.exp * 1000) > new Date().getTime();
}
示例5: currentUser
currentUser():User {
const jwt = localStorage.getItem('jwt');
if (!jwt) return;
const decoded = jwtDecode(jwt);
return {
id: decoded.userId,
email: decoded.sub,
}
}
示例6: parseJWT
parseJWT(jwt: string): any {
var jwtDecoded = null;
if (typeof jwt !== 'undefined' && jwt !== 'undefined' && jwt !== '') {
var jwtDecode = require('jwt-decode');
try { jwtDecoded = jwtDecode(jwt); } catch(e) { jwtDecoded = null; }
}
return jwtDecoded;
}
示例7: isTokenExpired
isTokenExpired(token) {
try {
const decoded = decode(token)
if (decoded.exp < Date.now() / 1000) { // Checking if token is expired. N
return true
}
else
return false
}
catch (err) {
return false
}
}
示例8: canActivate
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
// this will be passed from the route config
// on the data property
const expectedRole = route.data.expectedRole;
const token = localStorage.getItem('token');
// decode the token to get its payload
const tokenPayload = decode(token);
if (this.auth.isAuthenticated()) {
if (!isEmpty(route.data)) {
if (tokenPayload.sub.role !== expectedRole) {
this.router.navigate(['/workschedule']);
} else {
return true;
}
} else {
return true;
}
} else {
// not logged in so redirect to login page with the return url
this.router.navigate(['/login'], { queryParams: { returnUrl: state.url }});
}
}
示例9: constructor
constructor(public type: string, public http: Http) {
this.jwt = localStorage.getItem('jwt');
this.decodedJwt = this.jwt && jwtDecode(this.jwt);
}
示例10: constructor
constructor(public router: Router, public http: Http, public authHttp: AuthHttp) {
this.jwt = localStorage.getItem('jwt');
this.decodedJwt = this.jwt && jwtDecode(this.jwt);
}